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;

  • 相关阅读:
    window 编译lua 5.3
    邮件服务器软件
    mkyaffs2image 生成不了120M的镜像文件的解决方法
    C static struct
    uboot 如何向内核传递参数
    linux 链接理解
    snmp 协议之理解
    交叉编译知识点总结
    回滚原理 Since database connections are thread-local, this is thread-safe.
    REST 架构的替代方案 为什么说GraphQL是API的未来?
  • 原文地址:https://www.cnblogs.com/cute/p/2570063.html
Copyright © 2011-2022 走看看