[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] QApplication was not created in the main()
From:       Alan Ezust <alan.ezust () gmail ! com>
Date:       2014-07-28 17:25:49
Message-ID: CALy5K9pkPAKr4rTJyi_kt7B987SDx5+KG0vbLPqQjHpZ1wV1dA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I am not sure, I haven't tried what you are trying to do.

Perhaps if you are consistent about creating all QWidgets in the same
thread as your QApplication, and the one and only QApplication is created
as a stack variable in a function before any of the QWidgets are created,
and you have proper parent-child relationships between QObjects that never
cross thread boundaries, your program might work in another thread...

To better understand the topic, you should read
http://qt-project.org/doc/qt-5/thread-basics.html

GUI Thread and Worker Thread

As mentioned, each program has one thread when it is started. This thread
is called the "main thread" (also known as the "GUI thread" in Qt
applications). The Qt GUI must run in this thread. All widgets and several
related classes, for example QPixmap
<http://qt-project.org/doc/qt-5/qpixmap.html>, don't work in secondary
threads. A secondary thread is commonly referred to as a "worker thread"
because it is used to offload processing work from the main thread."






On Mon, Jul 28, 2014 at 9:41 AM, Gelonida N <gelonida@gmail.com> wrote:

> On 7/28/2014 6:18 PM, Alan Ezust wrote:
>
>>
>>
>>
>> On Mon, Jul 28, 2014 at 7:14 AM, Gelonida N <gelonida@gmail.com
>> <mailto:gelonida@gmail.com>> wrote:
>>
>>     Hi Alan,
>>
>>     On 7/26/2014 7:35 PM, Alan Ezust wrote:
>>
>>         You are only supposed to create one QApplication, and that should
>> be
>>         main. Why do you want to create a second one somewhere else? That
>> is
>>         probably a mistake.
>>
>>
>>     I think I did not express myself very well.
>>
>>     I do not want to create a second instance of a QApplication.
>>     I just want to know whether I can create an application from a
>>     thread which is NOT the main thread.
>>
>>
>> Why would you want to? What problem does it solve?
>>
>
> Main reason is because I want :-P to have my liberties and I want to
> understand where limitations come from.
>
> Another reason is, that I have some existing code, which does already
> something in the main thread and which has a  threading server, which shall
> create and start a QApplication under certain situations. Restructuring the
> code such, that the QApplication would start in the mean thread would be a
> little annoying and cost me some refactoring.
>
> On the other side I want to understand what a certain warning means, why
> it is where and which impact it might have.
>
>
> Another reason is, that I am doing some experiments with Ipython, Ipython
> kernels, applications being able to run headless or with GUI with a debug
> console or without and that at the moment IPython and QApplication want to
> execute in the main thread.
> There seems to be a mode, where both can share the same thread but so far
> I didn't find example code being able to do so. So the quickest solution
> would be to move the QApplication away from the main thread.
>
> By the way I will probably post a similiar question to the IPython mailing
> list in order to understand, why IPython insists on being run in the main
> thread.
>
>
>      I do not intend to create multiple QApplications, but wanted to
>>     know, what is so special about the main thread and why PyQt tells
>>     me, that I should create my GUI in the main thread.
>>
>>
>> That is a Qt limitation, not just a PyQt limitation. Because the GUI
>> classes are not thread-safe.
>> Other languages/frameworks have similar restrictions.
>>
>
> I don't agree. If code is not thread safe you're not allowed to call code
> from multiple threads without precautions and further knowledge.
>
> However whether you start non thread safe code in thread A or in thread B
> should not matter.
>
> So I expect there's another reason for the warning,, which I'd like to
> learn.
>
> I'd like to understand it and if there's no blocking point to learn how I
> can get rid of this warning.
>
>

[Attachment #5 (text/html)]

<div dir="ltr"><div>I am not sure, I haven&#39;t tried what you are trying to \
do.<br><br>Perhaps if you are consistent about creating all QWidgets in the same  \
thread as your QApplication, and the one and only QApplication is  created as a stack \
variable in a function before any of the QWidgets are  created, and you have proper \
parent-child relationships between QObjects that never cross thread boundaries, your \
program might work in another thread...<br><br></div><div>To better understand the \
topic, you should read <br> <a \
href="http://qt-project.org/doc/qt-5/thread-basics.html">http://qt-project.org/doc/qt-5/thread-basics.html</a><br><br><h3>GUI \
Thread and Worker Thread</h3> <p>As mentioned, each program has one thread when it is \
started. This  thread is called the &quot;main thread&quot; (also known as the \
&quot;GUI thread&quot; in Qt  applications). The Qt GUI must run in this thread. All \
widgets and  several related classes, for example <a \
href="http://qt-project.org/doc/qt-5/qpixmap.html">QPixmap</a>,  don&#39;t work in \
secondary threads. A secondary thread is commonly  referred to as a &quot;worker \
thread&quot; because it is used to offload  processing work from the main \
thread.&quot;</p><p><br></p></div><br><div><br></div></div><div \
class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 28, 2014 at 9:41 AM, \
Gelonida N <span dir="ltr">&lt;<a href="mailto:gelonida@gmail.com" \
target="_blank">gelonida@gmail.com</a>&gt;</span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div class="">On 7/28/2014 6:18 PM, Alan Ezust wrote:<br> \
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div class=""> <br>
<br>
<br>
On Mon, Jul 28, 2014 at 7:14 AM, Gelonida N &lt;<a href="mailto:gelonida@gmail.com" \
target="_blank">gelonida@gmail.com</a><br></div><div class=""> &lt;mailto:<a \
href="mailto:gelonida@gmail.com" target="_blank">gelonida@gmail.com</a>&gt;&gt; \
wrote:<br> <br>
      Hi Alan,<br>
<br>
      On 7/26/2014 7:35 PM, Alan Ezust wrote:<br>
<br>
            You are only supposed to create one QApplication, and that should be<br>
            main. Why do you want to create a second one somewhere else? That is<br>
            probably a mistake.<br>
<br>
<br>
      I think I did not express myself very well.<br>
<br>
      I do not want to create a second instance of a QApplication.<br>
      I just want to know whether I can create an application from a<br>
      thread which is NOT the main thread.<br>
<br>
<br>
Why would you want to? What problem does it solve?<br>
</div></blockquote>
<br>
Main reason is because I want :-P to have my liberties and I want to understand where \
limitations come from.<br> <br>
Another reason is, that I have some existing code, which does already something in \
the main thread and which has a   threading server, which shall create and start a \
QApplication under certain situations. Restructuring the code such, that the \
QApplication would start in the mean thread would be a little annoying and cost me \
some refactoring.<br>

<br>
On the other side I want to understand what a certain warning means, why it is where \
and which impact it might have.<br> <br>
<br>
Another reason is, that I am doing some experiments with Ipython, Ipython kernels, \
applications being able to run headless or with GUI with a debug console or without \
and that at the moment IPython and QApplication want to execute in the main \
thread.<br>

There seems to be a mode, where both can share the same thread but so far I \
didn&#39;t find example code being able to do so. So the quickest solution would be \
to move the QApplication away from the main thread.<br> <br>
By the way I will probably post a similiar question to the IPython mailing list in \
order to understand, why IPython insists on being run in the main thread.<div \
class=""><br> <br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">  I do not intend to create multiple QApplications, but \
                wanted to<br>
      know, what is so special about the main thread and why PyQt tells<br>
      me, that I should create my GUI in the main thread.<br>
<br>
<br>
That is a Qt limitation, not just a PyQt limitation. Because the GUI<br>
classes are not thread-safe.<br>
Other languages/frameworks have similar restrictions.<br>
</blockquote>
<br></div>
I don&#39;t agree. If code is not thread safe you&#39;re not allowed to call code \
from multiple threads without precautions and further knowledge.<br> <br>
However whether you start non thread safe code in thread A or in thread B should not \
matter.<br> <br>
So I expect there&#39;s another reason for the warning,, which I&#39;d like to \
learn.<br> <br>
I&#39;d like to understand it and if there&#39;s no blocking point to learn how I can \
get rid of this warning.<br> <br>
</blockquote></div><br></div>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic