Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to make signals and slots working in a console application? (Event loop not working)

How to make signals and slots working in a console application? (Event loop not working)

Scheduled Pinned Locked Moved Solved General and Desktop
event loopsignal & slot
4 Posts 3 Posters 2.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    robro
    wrote on 4 Jul 2018, 11:16 last edited by
    #1

    Hello,

    I have a console application and my main looks basically like that:

    #include "myclass"
    #include <QCoreApplication>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        MyClass myClass;
        myClass.process();
    
       return a.exec();
    

    "MyClass" is not derived from Qt but in this class another class is instantiated and this is derived from QObject, has the QObject-Marcro and needs a working signal-slot-machanism.

    What is necessary that this works?

    Thank you very much!

    V 1 Reply Last reply 4 Jul 2018, 11:19
    0
    • R robro
      4 Jul 2018, 11:16

      Hello,

      I have a console application and my main looks basically like that:

      #include "myclass"
      #include <QCoreApplication>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          MyClass myClass;
          myClass.process();
      
         return a.exec();
      

      "MyClass" is not derived from Qt but in this class another class is instantiated and this is derived from QObject, has the QObject-Marcro and needs a working signal-slot-machanism.

      What is necessary that this works?

      Thank you very much!

      V Offline
      V Offline
      VRonin
      wrote on 4 Jul 2018, 11:19 last edited by
      #2

      @robro said in How to make signals and slots working in a console application? (Event loop not working):

      What is necessary that this works?

      Nothing in particular, only that MyClass doesn't block the event loop, the typical case is running a while(true)

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      6
      • R Offline
        R Offline
        robro
        wrote on 4 Jul 2018, 11:35 last edited by
        #3

        Thanks,

        I do not understand this.
        If I would have a mainwindow, where would this loop be then?

        Where should I integrate this loop?
        Where and how could the event loop pause my code execution and execute the signal and slot things?
        Wouldn't I need different threads for that?

        J 1 Reply Last reply 4 Jul 2018, 11:43
        0
        • R robro
          4 Jul 2018, 11:35

          Thanks,

          I do not understand this.
          If I would have a mainwindow, where would this loop be then?

          Where should I integrate this loop?
          Where and how could the event loop pause my code execution and execute the signal and slot things?
          Wouldn't I need different threads for that?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 4 Jul 2018, 11:43 last edited by
          #4

          @robro You misunderstood what @VRonin wrote: you should NOT have such loops. Just use signals/slots in your app - there are no differences to UI apps.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          6

          4/4

          4 Jul 2018, 11:43

          • Login

          • Login or register to search.
          4 out of 4
          • First post
            4/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved