[Qt-interest] QThread Problem
Eirik Ulvik
eiriku at simsurgery.com
Thu Feb 11 15:26:20 CET 2010
Den 11.02.2010 15:13, skrev Yuvraj:
> Hi
>
> I want to run separate from main thread;
>
> My code is
>
> *my_thread.cpp*
>
> #include "my_thread.h"
> #include <QDebug>
> #include <QString>
>
> my_thread::my_thread()
> {
> this->start();
> moveToThread(this);
> }
Do not think you should start it from the constructor, and I really do
not understand why you are moving the tread....
> void my_thread::run()
> {
> this->exec();
> this->display();
>
> }
> void my_thread::display()
> {
> while(1)
> {
> qDebug() << "Sub thread is running";
> }
> }
> *my_thread.h
>
>
> #ifndef MY_THREAD_H
> #define MY_THREAD_H
> #include <QThread>
> #include "mainwindow.h"
> #include <QObject>
> class my_thread:public QThread
> {
> public:
> my_thread();
> void run();
> void display();
>
>
> };
>
>
> #endif // MY_THREAD_H
>
>
> i am calling the thread as follows
>
> my_thread thread;
> thread.run();
> *
this should be thread.start();
Calling run directly will make it run in the same thread as where it is
called from.
> *while(1)
> {
> qDebug() << "Main thread is running !!!\n";
> }
>
> is it correct ? If any thing wrong please let me know
>
>
> Thanks
>
> Yuvraj
>
> *
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100211/3b6bc08e/attachment.html
More information about the Qt-interest-old
mailing list