qtconcurrent

QtConcurrent::map segmentation fault

坚强是说给别人听的谎言 提交于 2021-01-29 04:11:13
问题 When I have been trying to implement "parallel for" using QtConcurrent::map: QFuture<void> parForAsync(size_t n, std::function<void (size_t)> Op) { size_t nThreads = static_cast<size_t>(QThreadPool::globalInstance()->maxThreadCount()); size_t nn = n/nThreads + 1; using Sequence = QVector<std::function<void()>>; Sequence vFuns; for(size_t i = 0; i < n; i+=nn) { size_t firstIdx = i, lastIdx = i + nn > n ? n : i + nn; vFuns.push_back([=]()->void { for(size_t i = firstIdx; i < lastIdx; ++i) { Op

QObject Cannot create children for a parent that is in a different thread

Deadly 提交于 2020-01-15 09:06:51
问题 Hi have need to do some socket communication from background, I used QtConcurrent::run to this, but giving me the warning. QObject: Cannot create children for a parent that is in a different thread. (Parent is MainWindow(0x7fff3e69f500), parent's thread is QThread(0x16f8070), current thread is QThread(0x17413d0) Here is the code, MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),ui(new Ui::MainWindow){ ui->setupUi(this); QFuture<void> f2 = QtConcurrent::run(this,&MainWindow:

What happens to the thread affinity of a QObject created within a worker thread which then terminates?

醉酒当歌 提交于 2020-01-12 03:08:06
问题 Let's say I call QtConcurrent::run() which runs a function in a worker thread, and in that function I dynamically allocate several QObjects (for later use). Since they were created in the worker thread, their thread affinity should be that of the worker thread. However, once the worker thread terminates, the QObject thread affinity should no longer be valid. The question: Does Qt automatically move the QObjects into the parent thread, or are we responsible in moving them to a valid thread

QtConcurrent::map() with member function = can not compile

梦想的初衷 提交于 2020-01-11 03:56:04
问题 My project is to create a small program which demonstrates the work of a search engine: indexing and returning result for arbitrary queries. I've done the work with the indexer part and now I want to improve it with indexing multiple files at once. The MainWindow class is here: class MainWindow : public QMainWindow { Q_OBJECT ..... private: Indexer * indexer; QStringList fileList; .... void index(QStringList list); void add(const QString &filename); } This is the implementation of add ( add

QtConcurrent with member function

自作多情 提交于 2019-12-24 19:45:23
问题 I create a QFuture that I want to use to parallelize calls to a member function. More precisely, I have a class solveParallel with .h : class solverParallel { public: solverParallelData(Manager* mgr_); virtual ~solverParallel(void); void runCompute(solveModel * model_); bool resultComput(); private: Manager *myMgr; QFuture<bool> myFutureCompute; }; where the methode runCompute() is creating the myFutureCompute member. .cpp looks like solveParallel::solveParallel(Manager* mgr_) :m_mgr(mgr_) {

Is it possible to modify QT qmake variable in the parent subdirs project?

情到浓时终转凉″ 提交于 2019-12-24 03:32:36
问题 I have the shared library project with structure like this: library.pro: TEMPLATE = subdirs CONFIG += ordered SUBDIRS += libs plugins test_programs ... QT += concurrent ... # Those files contains pure interfaces (C++ abstract classes) # with no implementation, and some helper classes with inline implementation. # So there is no reason to create yet another subproject for them HEADERS += iface/IInterface1.h \ iface/IInterface2.h \ # IInterface2 needs QtConcurrent ... IInterface2.h: ...

QRunnable - how to use it, examples

拜拜、爱过 提交于 2019-12-23 09:58:20
问题 Could point at some code using QRunnable as an alternative to QtConcurrent: I can't find any QRunnable example in Qtdoc. Did you ever try QRunnable AND QtConcurrent for same application, and could you comment on the compared performance? 回答1: QRunnable is an interface. So rather than looking for "a QRunnable example" it would be better to look for (for instance) "a QThreadPool example", such as: http://doc.qt.io/qt-4.8/thread-basics.html#example-1-using-the-thread-pool If you read further on

QT QCustomPlot in a new thread

匆匆过客 提交于 2019-12-11 14:33:30
问题 In my UI, I have a QCustomPlot and I have generatePlot function which uses from this QCustomPlot and runs in a new thread as follows: future = QtConcurrent::run(this, &MainWindow::generatePlot); In generatePlot function, I create QCPbars like this: QCPBars *bar = new QCPBars(customPlot->xAxis, customPlot->yAxis); But, I get this error : QObject: Cannot create children for a parent that is in a different thread. I think that's because the thread of customPlot is diffrenet from bar . How can I

How to use QtConcurrent::run with overloaded Function

只谈情不闲聊 提交于 2019-12-11 08:35:44
问题 I'm currently trying to parallelize my code, therefore I'm using QtConcurrent::run and the problem is, run doesn't know which function to choose. Is there a way to use run with an overloaded function or do I have find some sort of workaround? 回答1: You can just static_cast the pointer to ensure there's no ambiguity in the process void hello(QString name) { qDebug() << "Hello" << name << "from" << QThread::currentThread(); } void hello(int age) { qDebug() << "Hello" << age << "from" << QThread:

Qt terminate thread spawn by QConcurrent::run

我们两清 提交于 2019-12-10 11:16:55
问题 Platform: Win7 x64, MinGW-rubenvb (4.7.2-x64), Qt 4.8 Say I have few lengthy tasks (read population file, write population file, and run simulation) spawned using QConcurrent::run, as follow: void MainWindow::runLengthyJob() { /* some setup */ jobWatcher->setFuture(QConcurrent::run(theApp, &AppClass::lengthyJob)); // lengthyJob - can be readPop(), writePop(), runSim() } Usually those tasks take at least 15 seconds to finish (for simulation, it takes more than hours). To prevent crashing from