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
Forum Update on Monday, May 27th 2025

How to use functions of the QObject class in Visual Studio

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 453 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 15 Jun 2020, 10:39 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 !

    J J 2 Replies Last reply 15 Jun 2020, 10:41
    0
    • J JohnSRV
      15 Jun 2020, 10:39

      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 !

      J Offline
      J Offline
      JonB
      wrote on 15 Jun 2020, 10:41 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
        15 Jun 2020, 10:39

        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 !

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 15 Jun 2020, 12:00 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
        • V Offline
          V Offline
          VRonin
          wrote on 15 Jun 2020, 13:08 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

          2/4

          15 Jun 2020, 10:41

          • Login

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