当前位置: 首页>>代码示例>>C++>>正文


C++ QThread::connect方法代码示例

本文整理汇总了C++中QThread::connect方法的典型用法代码示例。如果您正苦于以下问题:C++ QThread::connect方法的具体用法?C++ QThread::connect怎么用?C++ QThread::connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QThread的用法示例。


在下文中一共展示了QThread::connect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: executeoperation

/**
 * Executes an operation (or workflow) and generates output
 * @param parameters the input and output parameters that the user filled in
 */
QString OperationCatalogModel::executeoperation(quint64 operationid, const QString& parameters, QVariant runparams) {

    try {
        IOperationMetaData metadata;
        metadata.prepare(operationid);
        auto opExpr = OperationExpression::createExpression(operationid, parameters);
        if ( metadata.isValid() && opExpr.isValid()){
            if ( metadata->resource().hasProperty("runinmainthread")){ // some operations may not run in a different thread. particular operations that invoke methods from the qml which must run in the mainthread
                OperationWorker::run(opExpr);
            }else {
                QThread* thread = new QThread;
                thread->setProperty("runparameters",runparams);
                OperationWorker* worker = new OperationWorker(opExpr);
                worker->moveToThread(thread);
                thread->setProperty("workingcatalog", qVariantFromValue(context()->workingCatalog()));
                thread->connect(thread, &QThread::started, worker, &OperationWorker::process);
                thread->connect(worker, &OperationWorker::finished, thread, &QThread::quit);
                thread->connect(worker, &OperationWorker::finished, worker, &OperationWorker::deleteLater);
                thread->connect(thread, &QThread::finished, thread, &QThread::deleteLater);
                thread->connect(worker, &OperationWorker::finished, this, &OperationCatalogModel::workerFinished);
                thread->start();

                return "TODO";

            }
        }
        return sUNDEF;
    } catch (const ErrorObject& err){
        emit error(err.message());
    }

    return sUNDEF;
}
开发者ID:52North,项目名称:IlwisCore,代码行数:37,代码来源:operationcatalogmodel.cpp

示例2: refreshCatalog

void MasterCatalogModel::refreshCatalog(const QString& path)
{
   // auto items = context()->workingCatalog()->items();
   // mastercatalog()->removeItems(items);

    QThread* thread = new QThread;
    CatalogWorker3* worker = new CatalogWorker3(path);
    worker->moveToThread(thread);
    thread->connect(thread, &QThread::started, worker, &CatalogWorker3::process);
    thread->connect(worker, &CatalogWorker3::finished, thread, &QThread::quit);
    thread->connect(worker, &CatalogWorker3::finished, worker, &CatalogWorker3::deleteLater);
    thread->connect(thread, &QThread::finished, thread, &QThread::deleteLater);
    thread->connect(worker, &CatalogWorker3::updateContainer, _currentCatalog, &CatalogModel::containerContentChanged);
    thread->start();

}
开发者ID:MartinSchouwenburg,项目名称:IlwisTest,代码行数:16,代码来源:mastercatalogmodel.cpp

示例3: longAction

void MasterCatalogModel::longAction()
{

    QThread *thr = new QThread;

    worker *w = new worker;

    w->moveToThread(thr);
    thr->connect(thr, &QThread::started, w, &worker::process);
    thr->start();
}
开发者ID:MartinSchouwenburg,项目名称:IlwisTest,代码行数:11,代码来源:mastercatalogmodel.cpp

示例4: CatalogModel

QList<CatalogModel *> MasterCatalogModel::startBackgroundScans(const std::vector<Ilwis::Resource>& catalogResources)
{
    QList<CatalogModel *> models;
    for(Resource resource : catalogResources){
        CatalogModel *cm = new CatalogModel(resource, CatalogModel::getCatalogType(resource));
        models.push_back(cm);
    }

    QThread* thread = new QThread;
    CatalogWorker* worker = new CatalogWorker(models, context()->workingCatalog());
    worker->moveToThread(thread);
    thread->connect(thread, &QThread::started, worker, &CatalogWorker::process);
    thread->connect(worker, &CatalogWorker::finished, thread, &QThread::quit);
    thread->connect(worker, &CatalogWorker::finished, worker, &CatalogWorker::deleteLater);
    thread->connect(thread, &QThread::finished, thread, &QThread::deleteLater);
    thread->connect(worker, &CatalogWorker::updateBookmarks, this, &MasterCatalogModel::updateBookmarks);
    thread->connect(worker, &CatalogWorker::finished, this, &MasterCatalogModel::initFinished);
    thread->start();

    return models;
}
开发者ID:MartinSchouwenburg,项目名称:IlwisTest,代码行数:21,代码来源:mastercatalogmodel.cpp

示例5: main

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    app.setOrganizationName("arksaw");
    app.setApplicationName("tisserver");

    // Initialize settings stuff
    QSettings::setDefaultFormat(QSettings::IniFormat);
    QSettings settings;
    settings.setValue("port", 50000);
    settings.sync();

    Console console;
    Database database;
    SessionManager sessionManager(0, &database);
    GameThread game(0, &database, &sessionManager);
    UdpServer udpServer;

    qRegisterMetaType<Packet>("Packet");
    qRegisterMetaType<QHostAddress>("QHostAddress");
    // Console signals/slots
    QObject::connect(&console, SIGNAL(commandEntered(CommandType,QStringList)),
                     &sessionManager, SLOT(runCommand(CommandType,QStringList)));
    QObject::connect(&console, SIGNAL(commandEntered(CommandType,QStringList)),
                     &game, SLOT(runCommand(CommandType,QStringList)),
                     Qt::DirectConnection); // Need direct connection from cross-thread signals to blocked thread
    QObject::connect(&console, SIGNAL(commandEntered(CommandType,QStringList)),
                     &udpServer, SLOT(runCommand(CommandType,QStringList)));

    // Database signals/slots
    QObject::connect(&database, SIGNAL(writeToConsole(QString)),
                     &console, SLOT(writeLine(QString)),
                     Qt::QueuedConnection);

    // SessionManager signals/slots
    QObject::connect(&sessionManager, SIGNAL(writeToConsole(QString)),
                     &console, SLOT(writeLine(QString)));
    QObject::connect(&sessionManager, SIGNAL(responseReady(Packet,QHostAddress,quint16)),
                     &udpServer, SLOT(sendResponse(Packet,QHostAddress,quint16)), Qt::QueuedConnection);

    // GameThread signals/slots
    QObject::connect(&game, SIGNAL(writeToConsole(QString)),
                     &console, SLOT(writeLine(QString)));
    QObject::connect(&game, SIGNAL(updatePacketReady(Packet)),
                     &sessionManager, SLOT(sendUpdatePacket(Packet)),
                     Qt::QueuedConnection);

    // UdpServer signals/slots
    QObject::connect(&udpServer, SIGNAL(writeToConsole(QString)),
                     &console, SLOT(writeLine(QString)));
    QObject::connect(&udpServer, SIGNAL(packetReceived(Packet,QHostAddress,quint16)),
                     &sessionManager, SLOT(processPacket(Packet,QHostAddress,quint16)),
                     Qt::DirectConnection);

    // Set up threading.
    QThread thread;
    game.moveToThread(&thread);
    thread.start();
    thread.connect(&thread, SIGNAL(finished()), &app, SLOT(quit()));

    // Invoke with Qt::QueuedConnection since the Qt event loop isn't up yet
    QMetaObject::invokeMethod(&database, "init", Qt::QueuedConnection);
    QMetaObject::invokeMethod(&sessionManager, "start", Qt::QueuedConnection);
    QMetaObject::invokeMethod(&game, "start", Qt::QueuedConnection);
    QMetaObject::invokeMethod(&udpServer, "start", Qt::QueuedConnection);

    // Run the primary thread's main event loop.
    // exec() will return when we stop the main event loop via a signal
    return app.exec();
}
开发者ID:ZackMattor,项目名称:tis,代码行数:70,代码来源:main.cpp

示例6: executeoperation


//.........这里部分代码省略.........

            //Add the duplicate name to the list of duplicate names
            if(occurences>1){
                duplicateFileNames = true;
                em->addError(1, "Workflow did not execute, multiple occurences of an output name");
            }

            QString formatName = parts[1];

            if ( operationresource.ilwisType() & itWORKFLOW) {
                QStringList existingFileNames;

                DIR *directory;

                //If not memory
                QString fileName;

                if(formatName == "Memory" ){
                    //Get all files in the internal catalog
                    QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/internalcatalog";
                    directory = opendir(dataLocation.toStdString().c_str());
                }else {
                    //Get all files in the directory
                    QString dataLocation = output;
                    dataLocation.remove("file:///");

                    QStringList splitUrl = dataLocation.split("/");

                    fileName = splitUrl.last();

                    QString query = "name='" + formatName + "'";
                    std::multimap<QString, Ilwis::DataFormat>  formats = Ilwis::DataFormat::getSelectedBy(Ilwis::DataFormat::fpNAME, query);
                    if ( formats.size() == 1){
                        QString connector = (*formats.begin()).second.property(DataFormat::fpCONNECTOR).toString();
                        QString code = (*formats.begin()).second.property(DataFormat::fpCODE).toString();

                        QVariantList extensions = Ilwis::DataFormat::getFormatProperties(DataFormat::fpEXTENSION,outputtype, connector, code);

                        fileName += ".";
                        fileName += extensions[0].toString();
                    }

                    splitUrl.removeLast();

                    dataLocation = splitUrl.join("/");

                    directory = opendir(dataLocation.toStdString().c_str());
                }

                struct dirent *file;

                //Put the existing file names in a list for later use
                while ((file = readdir (directory)) != NULL) {
                    existingFileNames.push_back(file->d_name);
                }

                closedir(directory);

                //Check if a file with the same name already exist
                for(int j=0;j<existingFileNames.size();++j){
                    if(formatName == "Memory"){
                        if(existingFileNames[j] == output) {
                            duplicateFileNames = true;
                            em->addError(1, "Workflow did not execute duplicate name: " + output + ". Please change this name.");
                        }
                    }else{
开发者ID:VincentBeltman,项目名称:IlwisCore,代码行数:67,代码来源:operationcatalogmodel.cpp


注:本文中的QThread::connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。