#include <QDebug>#include <QThread>#include <QString>#include <QtConcurrentRun>#include <QFuture>#include <QApplication>class foo{public: foo(QString str) { QtConcurrent::run(this, &foo::msg, str); }private: void msg(QString name) { qDebug() << "Hello" << name << "from" << QThread::currentThread(); }};int main(int argc, char **argv){ QApplication app(argc, argv); foo("Hello World!"); foo("Hello C++!"); foo("Hello Qt!"); app.exec();}
foo(QString str) { QFuture <void> threadFunc = QtConcurrent::run(this, &foo::msg, str); threadFunc.waitForFinished(); threadFunc.cancel(); }
void Note::loadDataNote(){ QSettings settingsINI(pathIni, QSettings::IniFormat); settingsINI.setIniCodec(QTextCodec::codecForName("windows-1251")); dataNote.globalPosX = settingsINI.value("GlobalPosX", 100).toInt(); dataNote.globalPosY = settingsINI.value("GlobalPosY", 100).toInt(); dataNote.width = settingsINI.value("Width", 200).toInt(); dataNote.height = settingsINI.value("Height", 200).toInt(); dataNote.title = settingsINI.value("Title", "").toString(); dataNote.lock = settingsINI.value("Lock", false).toBool(); dataNote.text = settingsINI.value("Text", "").toString(); dataNote.visible = settingsINI.value("Visible", true).toBool(); dataNote.opacityNote = settingsINI.value("Opacity", 100).toFloat() / 100; dataNote.colorNote = con.getColorFromHexColorForStyleSheet(color); dataNote.attribute = settingsINI.value("Attribute", "Default").toString(); dataNote.dateOfCreating = settingsINI.value("DateOfCreating", date).toString(); dataNote.dateLastChange = settingsINI.value("DateLastChange", date).toString(); dataNote.countTextSymbols = settingsINI.value("CountTextSymbols", 0).toInt(); dataNote.countTextLines = settingsINI.value("CountTextLines", 1).toInt(); dataNote.password = settingsINI.value("Password/Password", "").toString(); dataNote.protectionActive = settingsINI.value("Password/protectionActive", false).toBool();}void Note::saveDataNote(){ QSettings settingsINI(pathIni, QSettings::IniFormat); settingsINI.setIniCodec(QTextCodec::codecForName("windows-1251")); settingsINI.setValue("GlobalPosX", dataNote.globalPosX); settingsINI.setValue("GlobalPosY", dataNote.globalPosY); settingsINI.setValue("Width", dataNote.width); settingsINI.setValue("Height", dataNote.height); settingsINI.setValue("Title", dataNote.title); settingsINI.setValue("Lock", dataNote.lock); settingsINI.setValue("Text", dataNote.text); settingsINI.setValue("Visible", dataNote.visible); settingsINI.setValue("Opacity", int(dataNote.opacityNote * 100)); settingsINI.setValue("Color", color); settingsINI.setValue("Attribute", dataNote.attribute); settingsINI.setValue("DateOfCreating", dataNote.dateOfCreating); settingsINI.setValue("DateLastChange", dataNote.dateLastChange); settingsINI.setValue("CountTextSymbols", dataNote.countTextSymbols); settingsINI.setValue("CountTextLines", dataNote.countTextLines); settingsINI.setValue("Password/Password", dataNote.password); settingsINI.setValue("Password/protectionActive", dataNote.protectionActive); settingsINI.sync();}
threadFunc.waitForFinished(); threadFunc.cancel();
QFuture <void> threadFunc = QtConcurrent::run(this, &foo::msg, str); threadFunc.waitForFinished(); threadFunc.cancel();
#include <QDebug>#include <QThread>#include <QString>#include <QtConcurrentRun>#include <QFuture>#include <QApplication>#include <QtGui>class SleeperThread : public QThread{public: static void msleep(unsigned long msecs) { QThread::msleep(msecs); }};class foo{public: foo(QString str) { QFuture <void> threadFunc = QtConcurrent::run(this, &foo::msg, str); threadFunc.waitForFinished(); threadFunc.cancel(); }private: void msg(QString name) { qDebug() << "Hello" << name << "from" << QThread::currentThread(); }};void main(int argc, char **argv){ QApplication app(argc, argv); foo("Hello World!"); foo("Hello C++!"); foo("Hello Qt!"); SleeperThread::msleep(3000); foo("1"); foo("2"); app.exec();}