How to use functions of the QObject class in Visual Studio
-
Hello Everyone,
I'm using qt in Visual Studio 2017.
I'm trying to connect a signal to a slot usingQTcpServer*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.
Thanks !
-
Hello Everyone,
I'm using qt in Visual Studio 2017.
I'm trying to connect a signal to a slot usingQTcpServer*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.
Thanks !
@JohnSRV
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. -
Hello Everyone,
I'm using qt in Visual Studio 2017.
I'm trying to connect a signal to a slot usingQTcpServer*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.
Thanks !