Important: Please read the Qt Code of Conduct -

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 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.

    Thanks !

  • @JohnSRV
    Please start by using the new signal/slot syntax in all new code, as per e.g. It will then be much easier to diagnose what you have done wrong. Which will have nothing to do with Visual Studio.

  • Lifetime Qt Champion

    @JohnSRV To add to @JonB : where do you have this code? It needs to be in a QObject based class. There is no need for QObject:: at all.

  • Basically the main problem here seems to be that this is not a QObject class. This is not necessarily an issue if you use the new syntax as @JonB is suggesting

Log in to reply