Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use functions of the QObject class in Visual Studio

How to use functions of the QObject class in Visual Studio

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 450 Views
  • 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 Offline
    J Offline
    JohnSRV
    wrote on last edited by
    #1

    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 !

    JonBJ jsulmJ 2 Replies Last reply
    0
    • J JohnSRV

      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 !

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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
      5
      • J JohnSRV

        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 !

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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
        6
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          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
          4

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved