You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Sunday, April 1st 2012, 12:47am

QEventLoop and threads

Hi,

I use an event loop which works fine:

Source code

1
2
3
4
5
{
   QEventLoop loop;
   loop.connect(&qbox, SIGNAL(finished()), SLOT(quit()));
   loop.exec();
}


But if I call this within a thread (using pthread_t), I get the error message

Quoted

QPixmap: It is not safe to use pixmaps outside the GUI thread


Is there a way to use an event loop within a thread? Or is there another possibility to wait for a signal from an object without using an event loop?

2

Sunday, April 1st 2012, 9:40am

did you read the message? It refers to 'QPixmap' and 'outside gui thread'. So why are you asking unrelated question?

How do you think the normal event loop works if it isnt in a thread? Yes, event loop works fine in a thread.

Other possibilities for signals? Yes, there are hundreds of signals in Qt. Pick any that you want.


You cannot instantiate widgets in non-gui thread
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

3

Sunday, April 1st 2012, 10:07am

I'm not searching for other signals. Here is my problem:

I start a lot of threads, sometime it is necessary to get an input from the user but for this I can not leave the thread. That's why I'm opening a widget, ask the user for an input, wait (with an event loop) until the user finished and go on.

You said I cannot instantiate widgets in non-gui thread, so this would not work.

Is there a way to pause all threads, go into the gui thread, open the widget and get the user input and then resume the threads?

4

Sunday, April 1st 2012, 11:06am

you can't instantiate widget in threads

even, you can't do anything on them in threads

5

Sunday, April 1st 2012, 1:54pm

Ulf, that is exactly what a QDialog is for - it has its own event loop.

Nicolas, I believe that you can do what you want with widgets in other threads as long as it's not slot/signal related, or instantiation. It's probably not a good idea, but there is nothing stopping you from calling methods on widgets from another thread.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.