本文整理汇总了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;
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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{