Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    event loop signal & slot
    3
    4
    2081
    Loading More Posts
    • 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
      robro last edited by

      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!

      VRonin 1 Reply Last reply Reply Quote 0
      • VRonin
        VRonin @robro last edited by

        @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 Reply Quote 6
        • R
          robro last edited by

          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?

          jsulm 1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @robro last edited by

            @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 Reply Quote 6
            • First post
              Last post