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. Correct recevier object for connect

Correct recevier object for connect

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 2.0k 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.
  • McLionM Offline
    McLionM Offline
    McLion
    wrote on last edited by
    #1

    Hi

    I'm having issues getting the correct receiver object. Following connect returns expected primary-expression before ',' token

    DBGWebPage::DBGWebPage(QObject *parent) :
      QWebPage(parent)
    {
      connect(this, SIGNAL(LoLaSend(char, QByteArray, QByteArray)), QTGUI_MainWindow, SLOT(LoLaSend(char, QByteArray, QByteArray)));
    }
    
    bool DBGWebPage::shouldInterruptJavaScript()
    {
      qDebug() << "JavaScript needs too long ... stoped";
      emit LoLaSend(LOLA_ERROR,LOLA_TSK_QTGUI,"JavaScript timeout error");
      return true;    // stop the execution of JS
      //return false;   // continue the execution of the JS
    }
    
    class DBGWebPage : public QWebPage
    {
      Q_OBJECT
    
      public:
        explicit DBGWebPage(QObject *parent = 0);
        ~DBGWebPage();
      protected:
        void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
        void javaScriptAlert(QWebFrame * frame, const QString & msg);
        bool javaScriptConfirm(QWebFrame * frame, const QString & msg);
      public slots:
        bool shouldInterruptJavaScript();
      signals:
        char LoLaSend(char cClass, QByteArray qbTask, QByteArray qbMessage);
    };
    
    class QTGUI_MainWindow : public QMainWindow
    {
      Q_OBJECT
    ...
      public slots:
        char LoLaSend(char cClass, QByteArray qbTask, QByteArray qbMessage);
    ...
    };
    
    Probably something basic ... 
    Thanks
    E 1 Reply Last reply
    0
    • McLionM McLion

      Hi

      I'm having issues getting the correct receiver object. Following connect returns expected primary-expression before ',' token

      DBGWebPage::DBGWebPage(QObject *parent) :
        QWebPage(parent)
      {
        connect(this, SIGNAL(LoLaSend(char, QByteArray, QByteArray)), QTGUI_MainWindow, SLOT(LoLaSend(char, QByteArray, QByteArray)));
      }
      
      bool DBGWebPage::shouldInterruptJavaScript()
      {
        qDebug() << "JavaScript needs too long ... stoped";
        emit LoLaSend(LOLA_ERROR,LOLA_TSK_QTGUI,"JavaScript timeout error");
        return true;    // stop the execution of JS
        //return false;   // continue the execution of the JS
      }
      
      class DBGWebPage : public QWebPage
      {
        Q_OBJECT
      
        public:
          explicit DBGWebPage(QObject *parent = 0);
          ~DBGWebPage();
        protected:
          void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
          void javaScriptAlert(QWebFrame * frame, const QString & msg);
          bool javaScriptConfirm(QWebFrame * frame, const QString & msg);
        public slots:
          bool shouldInterruptJavaScript();
        signals:
          char LoLaSend(char cClass, QByteArray qbTask, QByteArray qbMessage);
      };
      
      class QTGUI_MainWindow : public QMainWindow
      {
        Q_OBJECT
      ...
        public slots:
          char LoLaSend(char cClass, QByteArray qbTask, QByteArray qbMessage);
      ...
      };
      
      Probably something basic ... 
      Thanks
      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @McLion said in Correct recevier object for connect:

      Probably something basic ...

      Maybe. Quickly looking, connect(this, SIGNAL(LoLaSend(char, QByteArray, QByteArray)), QTGUI_MainWindow, SLOT(LoLaSend(char, QByteArray, QByteArray))) has class name QTGUI_MainWindow instead of a pointer to an object.

      McLionM 1 Reply Last reply
      1
      • E Eeli K

        @McLion said in Correct recevier object for connect:

        Probably something basic ...

        Maybe. Quickly looking, connect(this, SIGNAL(LoLaSend(char, QByteArray, QByteArray)), QTGUI_MainWindow, SLOT(LoLaSend(char, QByteArray, QByteArray))) has class name QTGUI_MainWindow instead of a pointer to an object.

        McLionM Offline
        McLionM Offline
        McLion
        wrote on last edited by
        #3

        @Eeli-K
        Yes, that's the point. My problem is: What is the object to use as receiver for the MainWindow?

        E 1 Reply Last reply
        0
        • McLionM McLion

          @Eeli-K
          Yes, that's the point. My problem is: What is the object to use as receiver for the MainWindow?

          E Offline
          E Offline
          Eeli K
          wrote on last edited by
          #4

          @McLion said in Correct recevier object for connect:

          @Eeli-K
          Yes, that's the point. My problem is: What is the object to use as receiver for the MainWindow?

          Of course you have to first have created an instance of QTGUI_MainWindow somewhere. Look at the Qt documentation / Qt Creator examples, it's a basic task for any GUI app, if you don't have it already. Pass it to the DBGWebPage constructor or use some getMainWindow() static function or something like that to get the pointer.

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

            Hi,

            Aren't you trying to connect stuff at the wrong level ?

            You are likely going to create DBGWebPage object from an instance of QTGUI_MainWindow, no ? If so then do the connection in your QTGUI_MainWindow instance.

            DBGWebPage shouldn't care what is going to connect to it's LoLaSend signal, that's not its concern.

            On a side note, using the exact same name for both a signal and a slot in different classes is a bad idea, that makes the code very confusing to read.

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

            E 1 Reply Last reply
            4
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              The right way to do it is to add a signal to DBGWebPage

              signals:
              void LoLaSend(char, QByteArray, QByteArray);
              

              then use this where you use QTGUI_MainWindow now

              and from the main window connect to the signal in DBGWebPage. It's just a forwarding of the signal

              "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
              1
              • SGaistS SGaist

                Hi,

                Aren't you trying to connect stuff at the wrong level ?

                You are likely going to create DBGWebPage object from an instance of QTGUI_MainWindow, no ? If so then do the connection in your QTGUI_MainWindow instance.

                DBGWebPage shouldn't care what is going to connect to it's LoLaSend signal, that's not its concern.

                On a side note, using the exact same name for both a signal and a slot in different classes is a bad idea, that makes the code very confusing to read.

                E Offline
                E Offline
                Eeli K
                wrote on last edited by Eeli K
                #7

                @SGaist said in Correct recevier object for connect:

                Aren't you trying to connect stuff at the wrong level ?

                You are likely going to create DBGWebPage object from an instance of QTGUI_MainWindow, no ? If so then do the connection in your QTGUI_MainWindow instance.

                DBGWebPage shouldn't care what is going to connect to it's LoLaSend signal, that's not its concern.

                In other words, in DBGWebPage you always know when you want to send a signal. If at the time of sending the signal [edit: at the time of the writing the code] you already know the receiver, you don't need a signal at all, you can just call the receiver's function directly. The idea of signals/slots is that the sender doesn't have to have any knowledge of the receiver (or even vice versa).

                1 Reply Last reply
                0
                • McLionM Offline
                  McLionM Offline
                  McLion
                  wrote on last edited by McLion
                  #8

                  @SGaist, @VRonin
                  OK, moved the connect to the QTGUI_MainWindow instance where I create the DBGWebPage:

                    DBGWebPage *NewPage = new DBGWebPage(webGUI);
                    connect(NewPage, SIGNAL(LoLaSend(char, QByteArray, QByteArray)), this, SLOT(LoLaSend(char, QByteArray, QByteArray)));
                    webGUI->setPage(NewPage);
                  

                  Works now.
                  Thank you guys!

                  @Eeli-K
                  I tried to do it without signal/slots, which was my first approach, but did not get it to work.
                  (cannot call member function '.....' without object)

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

                    From what you are describing, you likely wrote something along the lines of QTGUI_MainWindow.LoLaSend(...), correct ?

                    If so that's why it is complaining, .LoLaSend must be called from an instance of QTGUI_MainWindow.

                    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

                    • Login

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