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. InvokeMethod on QTcpSocket

InvokeMethod on QTcpSocket

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.6k 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.
  • E Offline
    E Offline
    eddystefes
    wrote on last edited by
    #1

    Hi,

    i am trying to invoke "write" on a tcp socket that is in another thread:

    @
    QTcpSocket* my_socket_in_other_thread = new QTcpSocket();
    my_socket_in_other_thread.connect(...);
    ...

    QThread* the_thread = new QThread();
    my_socket_in_other_thread.moveToThread(the_thread);
    the_thread.start();

    ...

    QMetaObject::invokeMethod(my_socket_in_other_thread,
    "write",
    Qt::QueuedConnection,
    Q_RETURN_ARG(qint64,ret),
    Q_ARG(const QByteArray&,data));
    @

    but this get me the error:

    QMetaObject::invokeMethod: No such method QTcpSocket::write(const QByteArray&)

    what am i doing wrong?

    eddy

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

      Hi and welcome to devnet,

      You can't call write like that, it's not a slot nor a Q_INVOKABLE 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
      0
      • E Offline
        E Offline
        eddystefes
        wrote on last edited by
        #3

        so what is the proper way to send data throug a socket thats in an eventloop of QThread?

        Do i need to subclass QThread or make a wrappercalss for QTcpSocket?

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

          The worker object paradigm would be appropriate

          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 Extensions
          • Unsolved