Correct recevier object for connect
-
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
-
@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.
-
@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.
-
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.
-
The right way to do it is to add a signal to
DBGWebPage
signals: void LoLaSend(char, QByteArray, QByteArray);
then use
this
where you useQTGUI_MainWindow
nowand from the main window connect to the signal in DBGWebPage. It's just a forwarding of the signal
-
@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).
-
@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) -
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.