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. Socket doesn't fire "Connected()" signal

Socket doesn't fire "Connected()" signal

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 5 Posters 2.1k Views 3 Watching
  • 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
    rackover
    wrote on last edited by
    #3

    @kshegunov said in Socket doesn't fire "Connected()" signal:

    Use the Qt5 connect syntax and make sure you have success in establishing the signal-slot connection (i.e. QObject::connect returns true).

    Every one of these four connects return true. Imma see if I can convert this syntax to the QT5 syntax. Could it be that ? I'd prefer to stick to the old syntax if possible.

    aha_1980A 1 Reply Last reply
    0
    • R rackover

      @kshegunov said in Socket doesn't fire "Connected()" signal:

      Use the Qt5 connect syntax and make sure you have success in establishing the signal-slot connection (i.e. QObject::connect returns true).

      Every one of these four connects return true. Imma see if I can convert this syntax to the QT5 syntax. Could it be that ? I'd prefer to stick to the old syntax if possible.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @rackover

      the new syntax gives you compile time checking. if connect returns true, then the old syntax should work fine, too.

      looking at your snippet (from my limited phone sceen), may it be that socket is a stack variable and goes out of scope? create it on the heap then.

      Regards

      Qt has to stay free or it will die.

      kshegunovK 1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #5

        Hi,

        From the looks of it, you are initiating a new connection while there's no event loop running yet.

        I'd recommend ensuring that it's properly started before doing it. You can use a single shot QTimer for that purpose for example.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • aha_1980A aha_1980

          @rackover

          the new syntax gives you compile time checking. if connect returns true, then the old syntax should work fine, too.

          looking at your snippet (from my limited phone sceen), may it be that socket is a stack variable and goes out of scope? create it on the heap then.

          Regards

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #6

          @aha_1980 said in Socket doesn't fire "Connected()" signal:

          may it be that socket is a stack variable and goes out of scope?

          auto-storage with public scope *wink*

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          1
          • R Offline
            R Offline
            rackover
            wrote on last edited by
            #7

            The event loop should already be started when this code runs, since it's called from a Main function which is started with a QTimer like you said.

            Here is the github page of this project, so you can have a better overview of the code :

            The file which I took the code from : https://github.com/Rackover/PicoFAF/blob/master/serverlink.cpp
            Main loop : https://github.com/Rackover/PicoFAF/blob/master/main.cpp

            How can I check if the socket is creating out of scope ? If I create it on the heap, will I still be able to access it after that ?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              The Run method doesn't do much. It declares some variables, do some connections and then it's finished so all these variables are destroyed and nothing will happen.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              3
              • R Offline
                R Offline
                rackover
                wrote on last edited by
                #9

                The run method is instanciating the server variable which will create the socket and start connecting, logging in and fire other stuff (look at the server.cpp). Isn't it ? That's how I wrote it but maybe I'm wrong.

                jsulmJ 1 Reply Last reply
                0
                • R rackover

                  The run method is instanciating the server variable which will create the socket and start connecting, logging in and fire other stuff (look at the server.cpp). Isn't it ? That's how I wrote it but maybe I'm wrong.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by jsulm
                  #10

                  @rackover What @SGaist is saying: all variables inside Run() are LOCAL variables allocated on the stack and are destroyed as soon as Run() finishes!

                  // All this variables only exist while Run() is being executed. As soon as Run() finishes they are all destroyed!
                  Pico::Logging::Funcs logging;
                  Pico::Server::Funcs server;
                  Pico::Display::Funcs display;
                  Pico::Input::Funcs input;
                  Pico::Games::Funcs games;
                  Pico::Downloader::Funcs downloader;
                  

                  Make this variables class members.

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

                  1 Reply Last reply
                  3
                  • R Offline
                    R Offline
                    rackover
                    wrote on last edited by rackover
                    #11

                    But if those variables are created within the Mainframe class definition, since some of them (like server) contains code to execute on instanciation, won't this make code run before the event loop is started ?

                    If server is instantiated before the loop starts, the socket events won't trigger anyway, will they ?

                    jsulmJ 1 Reply Last reply
                    0
                    • R rackover

                      But if those variables are created within the Mainframe class definition, since some of them (like server) contains code to execute on instanciation, won't this make code run before the event loop is started ?

                      If server is instantiated before the loop starts, the socket events won't trigger anyway, will they ?

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @rackover Simply add them as POINTERS in your class and create instances in Run(), then they will be initialized in Run(), but will not be destroyed when Run() finishes:

                      // In class
                      private:
                          Pico::Logging::Funcs *logging;
                          Pico::Server::Funcs *server;
                          Pico::Display::Funcs *display;
                          Pico::Input::Funcs *input;
                          Pico::Games::Funcs *games;
                          Pico::Downloader::Funcs *downloader;
                      
                      // In Run()
                      logging = new Pico::Logging::Funcs();
                      ...
                      

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

                      1 Reply Last reply
                      3

                      • Login

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