System tray icon does not respond

When I open the application, the application is waiting for a connection to the server, I did this by calling the slot run()that is waiting for the confirmation packet from the server and when it receives it, then it hides the "Waiting for connection" and loads other things. The problem is that when it waits for a package, the icon in the system tray does not respond to anything, when the server sends the download of packages and applications, then the icon in the system panel starts responding (for the context menu).

I am using ZeroMQ for IPC.

I have something like this:

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show(); 

    //THIS PART
    QTimer::singleShot(2000,&w,SLOT(run()));

    return a.exec();
}
+4
source share
2 answers

. . , ZMQ . , .

, , .

ZMQ, . ZMQ / QMetaObject::invokeMethod, .

. Thread.

class ZMQ : public QObject {
  Q_OBJECT
  Q_SLOT void run() {
    ...
    forever {
      socket.send(request,0);
      socket.recv(&response);
      if(response.compare("login") == 0) {
        emit loggedIn();
        socket.close();
        return;
      }
    }
  }
public:
  ZMQ() {}
  Q_SIGNAL void loggedIn();
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    ZMQ zmq;
    Thread thread; // see /questions/1199941/how-to-safely-destruct-a-qthread/3904805#3904805
    MainWindow w;

    w.connect(&zmq, SIGNAL(loggedIn()), SLOT(loggedIn()));
    zmq.moveToThread(&thread);
    thread.start();

    QMetaObject::invokeMethod(&zmq, "run");

    w.show(); 
    return a.exec();
}
+3

Mainwindow:: run() , .

QObject , , . - :

QThread *thread = new QThread;
thread->start();
qobject_with_run_slot->moveToThread(thread);
QTimer::singleShot(2000, qobject_with_run_slot, SLOT(run()));
0

All Articles