Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to Call a function from thread entry point;
Qt 6.12 LTS is out! See what's new in the release blog

How to Call a function from thread entry point;

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 4.0k Views 1 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.
  • X Offline
    X Offline
    xmaze
    wrote on last edited by
    #3

    i use the pthread lib, it is a C code and i try to make a gui, but if the entrypoint is not static function then i have an error: cannot convert 'MainWindow::readerThreadEntryPoint' from type 'void* (MainWindow::)(void*)' to type 'void* ()(void)'

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Since you are using Qt, why don't you use QThread ?

      By the way, are you sure you need threading at all ? Qt's network operations are already synchronous.

      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
      0
      • X Offline
        X Offline
        xmaze
        wrote on last edited by
        #5

        i dont know how to use Qthread and i am confused.
        If i use @connect( socket, SIGNAL(readyRead()), this, SLOT(readTcpData()) );@ looks to work false. Updates the buffer before makes the process of the data.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #6

          [quote author="xmaze" date="1424469708"] Updates the buffer before makes the process of the data. [/quote]

          What do you mean by that ?

          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
          0
          • X Offline
            X Offline
            xmaze
            wrote on last edited by
            #7

            the program copy the data from the TCP port to the data buffer ,
            the second thread read this buffer and make the process.
            If i use the signal, then the programm writes the new bytes to data buffer before the second thread make the process. that means that i lose the data.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mfeemster
              wrote on last edited by
              #8

              You are describing concurrent programming, which is an entirely different, and advanced, subject.

              Looks up single producer, single consumer queues. Boost has a nice one.

              github.com/mfeemster/fractorium/wiki

              1 Reply Last reply
              0
              • X Offline
                X Offline
                xmaze
                wrote on last edited by
                #9

                Solution found for the call, i changed this line

                @pthread_create(&Modes.reader_thread, NULL, readerThreadEntryPoint, NULL); @

                to this one

                @pthread_create(&Modes.reader_thread, NULL, readerThreadEntryPoint, this); @

                I wrote the following code in header, and i wrote some code in function readTCPdata();

                @void readTCPdata(void);
                static void
                readerThreadEntryPoint(void arg) { return ((MainWindow)arg)->readTCPdata(); } @

                The thread is working but cannot read the data, only make a call without results!

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  Any error message on the console ?

                  By the way, you can't use a QTcpSocket created in one thread from another one.

                  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
                  0
                  • X Offline
                    X Offline
                    xmaze
                    wrote on last edited by
                    #11

                    [quote author="SGaist" date="1424554944"]Any error message on the console ?

                    By the way, you can't use a QTcpSocket created in one thread from another one.[/quote]

                    i don't have an error, the data Array it;s empty, How can i declare a QtcpSocket in a Thread;

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      Have a look at the Threaded Fortune Server example

                      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
                      0

                      • Login

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