Hi, I am new to C++ and Qt and despite that i am thinking of using threads in my app. Here is an example code which outputs "." and then "QThread: Destroyed while thread is still running" error after pressing button.
{
public:
void run();
};
void MyThread::run()
{
int connected=0;
while (connected==0)
{
fprintf(stderr,".");
//Do something that modifies num when usb device is connected
sleep(5);
}
}
void MainWindowImpl::on_button_clicked()
{
MyThread t;
t.start();
}
class MyThread : public QThread
{
public:
void run();
};
void MyThread::run()
{
int connected=0;
while (connected==0)
{
fprintf(stderr,".");
//Do something that modifies num when usb device is connected
sleep(5);
}
}
void MainWindowImpl::on_button_clicked()
{
MyThread t;
t.start();
}
To copy to clipboard, switch view to plain text mode
0
What can be wrong in this code? Am I not allowed to use while loop in thread?
Bookmarks