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. QML call function in C++ with threads

QML call function in C++ with threads

Scheduled Pinned Locked Moved Unsolved General and Desktop
qthreadsqmlqfutureqinvokableqmlc++
22 Posts 4 Posters 19.0k 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 jsulm
    4 Oct 2016, 08:27

    @jeremy_k I don't think the signals will be emitted. Signal/slots connections between two threads are not direct connections but queued connections.

    J Offline
    J Offline
    jeremy_k
    wrote on 4 Oct 2016, 09:06 last edited by
    #21

    @jsulm Pulling code from moc output I happen to have lying around:

    For a signal void stuffChanged(QString), moc generates:

    // SIGNAL 0
    void Singleton::stuffChanged(QString _t1)
    {
        void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
        QMetaObject::activate(this, &staticMetaObject, 0, _a);
    }
    

    QMetaObject::activate() is a private API in qtbase/src/corelib/kernel/qobject.cpp. The version that takes a pointer to the static meta object eventually calls this one:

    void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_index, void **argv)
    {
     ...
            if ((c->connectionType == Qt::AutoConnection && !receiverInSameThread)
                    || (c->connectionType == Qt::QueuedConnection)) {
                    queued_activate(sender, signal_index, c, argv ? argv : empty_argv, locker);
                    continue;
    ...
    }
    

    The full source is a little lengthy to quote here, but check it out if you're curious. Also, you can trace the emission of a signal through to the call of a slot for an object in the same thread without a return to the event loop with the debugger.

    To reiterate, signal emission is done when emit signal() returns. Calling of a particular slot may be pending for any queued connection.

    Asking a question about code? http://eel.is/iso-c++/testcase/

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Cleiton Bueno
      wrote on 4 Oct 2016, 12:07 last edited by
      #22

      I agree, this while() was bothering me.

      I'm using a _timer with QTimer where start() by clicking, I get the Socket data with onReadyRead() process met _timer.stop() but emito sign for the status, seems to be working well.

      But I accept suggestions for improvement, but I removed the loop while()

      1 Reply Last reply
      0

      21/22

      4 Oct 2016, 09:06

      • Login

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