Show message box in thread Qt

ساخت وبلاگ

آخرین مطالب

امکانات وب

Vote count: 0

I have wrote the following code: my main program:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
using namespace Qt;

MyThread mThread;

int main(int argc, char *argv[])
{
   QApplication a(argc, argv);
    if (g > 5)
    {
        if (!mThread.isRunning())
        {
            mThread.start();
        }
    }

    std::this_thread::sleep_for(std::chrono::hours(1));

}

My MyThread class cpp:

#include "mythread.h"

MyThread::MyThread(QObject *parent) : QThread(parent)
{

}

void MyThread::run()
{

   QMessageBox messageBox;
   messageBox.critical(0,"ERROR","SYSTEM NEEDS COOLING");
   messageBox.setFixedSize(500,200);

}

And my MyThread class hpp:

#ifndef MYTHREAD_H
#define MYTHREAD_H

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
using namespace Qt;

class MyThread : public QThread
{
   Q_OBJECT
public:
   explicit MyThread(QObject *parent = 0);

   void run();

};

#endif // MYTHREAD_H

I have simplified my program because the other part of it is to send an email but that part is working as well as the part of reading the PC temperature as the whole point of this program. And I need it to show a message box and keep running in order to send the mail but if message box exists dont show another one.

The problem that I get is that it shows an empty transparent message box that I cannt close but it still continues to run. or on the other hand if there is an option to make:

    QMessageBox messageBox;
    messageBox.critical("Error","SYSTEM NEEDS COOLING");               
    messageBox.setFixedSize(500,200);

and that the program will continue to run with out the need for the user to press the OK button it will be great (dont forget that the program will sleep for an hour so it is possible for the user to press the OK button while the main thread sleeps the secondary thread (MyThread should close on the event of the OK button pressed).

I got stucked as this program includes console program with widgets and threads. Thanks

asked 1 min ago
Qouqou

...
نویسنده : استخدام کار بازدید : 21 تاريخ : دوشنبه 21 خرداد 1397 ساعت: 0:00

close
تبلیغات در اینترنت