Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How to use functions of the QObject class in Visual Studio

    General and Desktop
    4
    4
    171
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      JohnSRV last edited by

      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 !

      JonB jsulm 2 Replies Last reply Reply Quote 0
      • JonB
        JonB @JohnSRV last edited by JonB

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

        1 Reply Last reply Reply Quote 5
        • jsulm
          jsulm Lifetime Qt Champion @JohnSRV last edited by

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

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply Reply Quote 6
          • V
            VRonin last edited by

            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

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply Reply Quote 4
            • First post
              Last post