Signal from Application class?
-
I've been writing an application for several weeks now, the main class is derived from QApplication.
class Trainer : public QApplicationToday I tried to implement a signal from the main application so that if an error occurs it emits a signal:
signals: void dbError(const QSqlError& crErr);When building this resulted in:
C2338: No Q_OBJECT in the class with the signalSo I added Q_OBJECT to the class and rebuilt, now the errors are:
LNK2019: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ... LNK2001: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...This is the actual emit in the class:
emit Trainer::mspApp->dbError(err);mspApp is defined as:
static Trainer* mspApp;Which is in the Trainer class and in the module:
Trainer* Trainer::mspApp = nullptr;This static pointer is initialised in the class constructor:
Trainer::mspApp = this;What am I not doing?
-
I've been writing an application for several weeks now, the main class is derived from QApplication.
class Trainer : public QApplicationToday I tried to implement a signal from the main application so that if an error occurs it emits a signal:
signals: void dbError(const QSqlError& crErr);When building this resulted in:
C2338: No Q_OBJECT in the class with the signalSo I added Q_OBJECT to the class and rebuilt, now the errors are:
LNK2019: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ... LNK2001: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...This is the actual emit in the class:
emit Trainer::mspApp->dbError(err);mspApp is defined as:
static Trainer* mspApp;Which is in the Trainer class and in the module:
Trainer* Trainer::mspApp = nullptr;This static pointer is initialised in the class constructor:
Trainer::mspApp = this;What am I not doing?
@SPlatten said in Signal from Application class?:
What am I not doing?
Did you do complete rebuild after adding Q_OBJECT macro?
-
@SPlatten said in Signal from Application class?:
What am I not doing?
Did you do complete rebuild after adding Q_OBJECT macro?
-
I've been writing an application for several weeks now, the main class is derived from QApplication.
class Trainer : public QApplicationToday I tried to implement a signal from the main application so that if an error occurs it emits a signal:
signals: void dbError(const QSqlError& crErr);When building this resulted in:
C2338: No Q_OBJECT in the class with the signalSo I added Q_OBJECT to the class and rebuilt, now the errors are:
LNK2019: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ... LNK2001: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...This is the actual emit in the class:
emit Trainer::mspApp->dbError(err);mspApp is defined as:
static Trainer* mspApp;Which is in the Trainer class and in the module:
Trainer* Trainer::mspApp = nullptr;This static pointer is initialised in the class constructor:
Trainer::mspApp = this;What am I not doing?
@SPlatten you don't have to reinvent the wheel you know, especially in relation to static QObjects, that are tricky in their own right. Especially as the instantiation order is important
you're deriving from QApplication, so you have the qApp macro at your disposal
#define qApp QCoreApplication::instance()or use the QCoreApplication::instance() call direct. and object cast it.
If you're copy pasted this, than you have an error in your code, as this should be QApplication not Application
class Trainer : public Application -
@SPlatten you don't have to reinvent the wheel you know, especially in relation to static QObjects, that are tricky in their own right. Especially as the instantiation order is important
you're deriving from QApplication, so you have the qApp macro at your disposal
#define qApp QCoreApplication::instance()or use the QCoreApplication::instance() call direct. and object cast it.
If you're copy pasted this, than you have an error in your code, as this should be QApplication not Application
class Trainer : public Application@J-Hilk, thank you, the reason I added my own static point is so I don't have to put in static casts where its used in order to reference the signals.
Sorry, again Application is supposed to read QApplication that was a typo adding this post, the laptop I'm using on has issues and cannot post to this forum. So I have to type it all in on my iMac.
-
@J-Hilk, thank you, the reason I added my own static point is so I don't have to put in static casts where its used in order to reference the signals.
Sorry, again Application is supposed to read QApplication that was a typo adding this post, the laptop I'm using on has issues and cannot post to this forum. So I have to type it all in on my iMac.
@SPlatten said in Signal from Application class?:
thank you, the reason I added my own static point is so I don't have to put in static casts where its used in order to reference the signals.
C++ dynamic_cast() or qobject_cast() NOT static_cast!
My heart š±
š -
@SPlatten said in Signal from Application class?:
thank you, the reason I added my own static point is so I don't have to put in static casts where its used in order to reference the signals.
C++ dynamic_cast() or qobject_cast() NOT static_cast!
My heart š±
š -
I've been writing an application for several weeks now, the main class is derived from QApplication.
class Trainer : public QApplicationToday I tried to implement a signal from the main application so that if an error occurs it emits a signal:
signals: void dbError(const QSqlError& crErr);When building this resulted in:
C2338: No Q_OBJECT in the class with the signalSo I added Q_OBJECT to the class and rebuilt, now the errors are:
LNK2019: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ... LNK2001: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...This is the actual emit in the class:
emit Trainer::mspApp->dbError(err);mspApp is defined as:
static Trainer* mspApp;Which is in the Trainer class and in the module:
Trainer* Trainer::mspApp = nullptr;This static pointer is initialised in the class constructor:
Trainer::mspApp = this;What am I not doing?
@SPlatten said in Signal from Application class?:
So I added Q_OBJECT to the class and rebuilt, now the errors are:
LNK2019: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...
LNK2001: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...The only reason I am aware about for this issue is that the MOC has not been called.
For QMake projects, you just have to rerun QMake (Build => run qmake), and rebuild the project.
For CMake projects, I don't know, there must be something equivalent.Or simply delete the build directory.