I am using 2 threads: GUI thread and 1 worker thread(grabthread),but i am not able to run them concurrently.
My main() function is like this :
int main(int argc, char *argv[])
{
MainWindow win;
win.show();
GrabThread thread;
thread.start();
qDebug() << "hello from GUI thread " << a.thread()->currentThreadId();
thread.wait(); // do not exit before the thread is completed!
return a.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow win;
win.show();
GrabThread thread;
thread.start();
qDebug() << "hello from GUI thread " << a.thread()->currentThreadId();
thread.wait(); // do not exit before the thread is completed!
return a.exec();
}
To copy to clipboard, switch view to plain text mode
and grabthread.h like this:
{
Q_OBJECT
private:
void run();
};
class GrabThread : public QThread
{
Q_OBJECT
private:
void run();
};
To copy to clipboard, switch view to plain text mode
What is happening is that My GUI pops up only after grabthread has been fully executed and exits.
I want my GUI and grabthread to start simultaneously so that i can use multithreading.
Bookmarks