Using Q_SIGNAL/Q_SLOT Dsiplays invalid Errors in QTCreator
-
Hello,
I modified my code to use Q_SIGNAL. Q_SLOT, and Q_EMIT. The .pro file has the following entry
CONFIG += no_keywordsI'm still getting a whole bunch of errors on standard code fragments which should be fine.
For example this line of code
connect(displayTimeWorkerThreadTimer, Q_SIGNAL(timeout()), displayLatestTimeWorker, Q_SLOT(getTime()));
is get "expected expression" errors. It was fine with the standard SIGNAL/SLOT.Even lines that have nothing to do with signal/slots is reporting errors.
Is there something else I need to add to the .pro file?
Also in the header I have signals/slots defined as
signals:
slots:Should it be
Q_SIGNALS:
Q_SLOTS:
instead? I tried that but it didn't seem to make a difference.Any help would be appreciated.
-
Hi
The Q_SIGNALS and Q_SLOTS are replacements for the
signals:
slots:
in the .h file
but as far as I know, NOT to be used for the connect.for connect, you should rather use the new syntax
https://wiki.qt.io/New_Signal_Slot_Syntax -
Hi,
One of the main difference is build time error rather than runtime warning.
-
I'm on 5.15.2 and have been using the old connect syntax with no issues. Why would the new syntax make a difference when I start using the Q_ declaration?
Hi
Its really not related as such.
The Q_SIGNALS is made to make it easier to avoid issues or clashes with other code where the slots: keywords are used for something else.The new syntax is compile time checking versus the old macro-based one that will eat almost anything at compile time
and silently fail at runtime. -
That's fine but if I'm not concerned about those issues. Is there a way I can use the Q_ declaration with the old syntax. My code works and there are no signal/slot issues so I'm not concerned about the compilation. Unfortunately I'm forced to use the Q_SIGNAL by forces outside my control within my company.
-
I did that but I still get connect errors inth ecompilation. Here is an example:
In my headers I define
Q_SIGNALS:
bblah ();Q_SLOTS:
bblah_blah();sample connect. Same error for all connect statements: (the error is "expected expression" and there is a red line under Q_SIGNAL and Q_SLOT)
connect(this, Q_SIGNAL(sendDataBaseNameAndTables(QString, QStringList)), displayLatestTimeWorker, Q_SLOT(getDataBaseNameAndTables(QString, QStringList)));
-
So you are saying, I should have this?
connect(this, SIGNAL(sendDataBaseNameAndTables(QString, QStringList)), displayLatestTimeWorker, SLOT(getDataBaseNameAndTables(QString, QStringList)));The way the header defines the signal/shot is how it is interpreted?
-
So you are saying, I should have this?
connect(this, SIGNAL(sendDataBaseNameAndTables(QString, QStringList)), displayLatestTimeWorker, SLOT(getDataBaseNameAndTables(QString, QStringList)));The way the header defines the signal/shot is how it is interpreted?