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. calling function with functions
Qt 6.11 is out! See what's new in the release blog

calling function with functions

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 6 Posters 815 Views 2 Watching
  • 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.
  • S Offline
    S Offline
    s002wjh
    wrote on last edited by
    #1

    if I have a class with function like this

    void test::listen()
    {
    QTcpServer::listen(QHostAddress::Any,1234);
    }

    how can I access QTcpServer::listen() from another file? something like this?

    test *tt = new test();

    tt->lisen()::QTcpServer::listen() ??

    ODБOïO JonBJ jsulmJ 3 Replies Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you aware that the listen function of QTcpServer is not a static method ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • S s002wjh

        if I have a class with function like this

        void test::listen()
        {
        QTcpServer::listen(QHostAddress::Any,1234);
        }

        how can I access QTcpServer::listen() from another file? something like this?

        test *tt = new test();

        tt->lisen()::QTcpServer::listen() ??

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        yes

        1 Reply Last reply
        1
        • S s002wjh

          if I have a class with function like this

          void test::listen()
          {
          QTcpServer::listen(QHostAddress::Any,1234);
          }

          how can I access QTcpServer::listen() from another file? something like this?

          test *tt = new test();

          tt->lisen()::QTcpServer::listen() ??

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

          @s002wjh
          You asked this and @jsulm answered you at https://forum.qt.io/topic/110393/check-port-in-use/8

          @jsulm said in check port in use:

          @s002wjh said in check port in use:

          can I do this without creating new tcpserver etc?

          No, because listen() is not static

          You need to understand static and that QTcpServer::listen() is not static and really is going to require you to create an instance of QTcpServer in order to call it :)

          1 Reply Last reply
          3
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by SGaist
            #5

            Hi
            You are a bit off.
            You need to have an instance and it has to be a member.

            class test {
            ...
            QTcpServer server;//instance
            }

            void test::listen()
            {
            server.listen(QHostAddress::Any,1234); // use the instance, listen cannot be used as static method
            }

            test *tt = new test();
            tt->listen();

            1 Reply Last reply
            2
            • S s002wjh

              if I have a class with function like this

              void test::listen()
              {
              QTcpServer::listen(QHostAddress::Any,1234);
              }

              how can I access QTcpServer::listen() from another file? something like this?

              test *tt = new test();

              tt->lisen()::QTcpServer::listen() ??

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

              @s002wjh said in calling function with functions:

              how can I access QTcpServer::listen() from another file?

              I really don't get what you want to do.
              To call QTcpServer::listen() in another file you do it in exact same way you do it in test (but create an QTcpServer instance as listen() is not static as I already told you). You really should read a book about C++.

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

              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