zoukankan      html  css  js  c++  java
  • Qt::AutoConnection 信号从不同于接收者的thread发出时是queued 方式触发

    qoject.cpp中的代码:

    static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connection *c, void **argv)
    {
        if (!c->argumentTypes && c->argumentTypes != &DIRECT_CONNECTION_ONLY) {
            QMetaMethod m = sender->metaObject()->method(signal);
            int *tmp = queuedConnectionTypes(m.parameterTypes());
            if (!tmp) // cannot queue arguments
                tmp = &DIRECT_CONNECTION_ONLY;
            if (!c->argumentTypes.testAndSetOrdered(0, tmp)) {
                if (tmp != &DIRECT_CONNECTION_ONLY)
                    delete [] tmp;
            }
        }
        if (c->argumentTypes == &DIRECT_CONNECTION_ONLY) // cannot activate
            return;
        int nargs = 1; // include return type
        while (c->argumentTypes[nargs-1])
            ++nargs;
        int *types = (int *) qMalloc(nargs*sizeof(int));
        Q_CHECK_PTR(types);
        void **args = (void **) qMalloc(nargs*sizeof(void *));
        Q_CHECK_PTR(args);
        types[0] = 0; // return type
        args[0] = 0; // return value
        for (int n = 1; n < nargs; ++n)
            args[n] = QMetaType::construct((types[n] = c->argumentTypes[n-1]), argv[n]);
        QCoreApplication::postEvent(c->receiver, new QMetaCallEvent(c->method_offset,
                                                                    c->method_relative,
                                                                    c->callFunction,
                                                                    sender, signal, nargs,
                                                                    types, args));

    }

    void QMetaObject::activate(QObject *sender, const QMetaObject *m, int local_signal_index,
                               void **argv)

    。。。。

    QObject * const receiver = c->receiver;
    const bool receiverInSameThread = currentThreadId == receiver->d_func()->threadData->threadId;

    // determine if this connection should be sent immediately or
    // put into the event queue
    if ((c->connectionType == Qt::AutoConnection && !receiverInSameThread)
        || (c->connectionType == Qt::QueuedConnection)) {
        queued_activate(sender, signal_absolute_index, c, argv ? argv : empty_argv);
        continue;

  • 相关阅读:
    6 完全平方数相关
    5 三位数,每个位置不同
    Neo4j Admin Import 导入多个node和relationship
    Rust所有权
    Rust 多态
    Rust 泛型
    Rust trait
    Rust模块化
    Spring Cloud(Dalston.SR1)
    git 速度慢问题解决
  • 原文地址:https://www.cnblogs.com/cute/p/2570063.html
Copyright © 2011-2022 走看看