Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to use functions of the QObject class in Visual Studio
JohnSRV last edited by
I'm using qt in Visual Studio 2017.
I'm trying to connect a signal to a slot using
QTcpServer*pTcpServer = new QTcpServer(); QObject::connect(pTcpServer, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
And I'm getting the following errors:
QObject::connect : illegal call of non-static member function
this: can only be referenced inside non-static member functions or non-static data member initializers.
I've done some research and found out that the first error means i need to create an instance of the class in order to call the function Connect. I tried to do that but i can't seem to find the right syntax to do it.
JonB last edited by JonB
Please start by using the new signal/slot syntax in all new code, as per e.g. https://wiki.qt.io/New_Signal_Slot_Syntax. It will then be much easier to diagnose what you have done wrong. Which will have nothing to do with Visual Studio.
VRonin last edited by
Basically the main problem here seems to be that
thisis not a
QObjectclass. This is not necessarily an issue if you use the new syntax as @JonB is suggesting