问题标签 [qtconcurrent]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
multithreading - 为使用 QtConcurrent 运行的线程设置堆栈大小
如何设置线程运行的堆栈大小QtConcurrent
?
multithreading - Qt QtConcurrent 进度条更新
我有一个QTableView
连接到一个QAbstractTableModel
.
该模型用于QtConcurrent::map
为应用程序创建线程(复制文件)
我进行了子类化QStyledItemDelegate
以在其中一个 tableviews 单元格中显示 a QStyleOptionProgressBar
,其想法是通过模型更新进度条。它有效,但一次从 0% 到 100%,并不顺利。
QAbstractTableModel::setData()
在我的“复制循环”中被调用,但似乎QAbstractTableModel::dataChanged()
只有在循环结束时才会发出。不管我做什么。
这可能是一种错误的方法,但我不知道如何从线程访问表格视图中的给定进度条。
c++ - boost::bind 和 qtconcurrent::map ...似乎无法使其工作
好吧,我需要你的帮助,因为我似乎找不到办法
QtConcurrent::map使用我的静态函数和我的元素序列。这是我正在尝试做的事情:
我想运行这个功能:
在这组元素上:
这是我为调用 map 所做的,但编译器不喜欢它......即使在阅读了所有 boost & Qt 文档之后,我也找不到正确的语法!
ps:显然这是C++
另外,请不要介意 boost::ref 调用,我只是在玩它。我要解决的是调用映射好的参数
谢谢你的帮助
qt - 关闭/中止 QProgressDialog 的问题
我现在正在将 GUI 添加到为控制台操作而编写的项目中。我选择了 Qt 作为框架,现在在处理 QProgressDialog 的关闭事件时遇到了困难。
问题 1:我使用 QtConcurrent::run 为一个长/繁重的任务分叉一个进程,并使用一个“等待”QProgressDialog(范围为 0,0)来提示用户长时间运行的进程。问题是我不能让对话框自行关闭!
要求1:如果可能,不要触摸/更改原包装的代码。
问题 2:如何链接“中止”按钮来终止 SimApplication::runSimulation()?
qt - 带有 QtConcurrent::run 的 Qt QTcpSocket 需要在单独的线程中进行事件循环
我在 Qt 中有一个 Web 服务器,它将读取一个非常大的(~1Gb)文件并通过 QTcpSocket 将数据返回给请求者。此套接字由主服务器线程创建。我想使用 QtConcurrent 将此套接字移交给工作线程并将数据发送回那里。
我的“returnPartialLargeFile”函数如下所示:
我得到的错误是,如果我将 'loop.exec()' 行注释掉,我会收到以下错误:
如果我取消注释,那么我的函数会在 exec() 行短路,并且永远不会向套接字写入数据,但是我没有收到任何错误,我只是得到一个不包含来自 while 循环的任何数据的截断响应.
我正在重新设置套接字并将其移至新线程,因此我希望我的问题仅与事件循环以及套接字信号和插槽有关。关于我在这里做错了什么的任何想法?我怎样才能让它工作?如果信号/插槽问题,我需要在这里连接哪个?谢谢 -
multithreading - QtConcurrent::run with functor
如何将 QtConcurrent::run 与函数对象一起使用?你能告诉我一个如何做到这一点的例子吗?
c++ - Qt 通过 QConcurrent::run 终止线程生成
平台:Win7 x64、MinGW-rubenvb (4.7.2-x64)、Qt 4.8
假设我有几个使用 QConcurrent::run 生成的冗长任务(读取填充文件、写入填充文件和运行模拟),如下所示:
通常这些任务至少需要 15 秒才能完成(对于模拟,需要几个小时以上)。为了防止尚未完成的线程崩溃,我重新实现 MainWindow::closeEvent 如下:
这可以正常工作,但是当我单击 MainWindow 的“x”按钮时,它似乎冻结并显示“无响应”(我猜文本是由操作系统给出的),尽管它最终终止了应用程序。
我想在触发 MainWindow 的 close() 插槽后立即退出应用程序。那么,如何缩短未完成线程的等待时间呢?或者我如何通知用户仍有一个冗长的作业正在运行(可能需要数小时才能完全关闭)?(我试图在 closeEvent 中包含 QDialog/QMessagebox,但新创建的小部件也冻结了)
注意:对于 AppClass:longyJobs [readPop() /writePop()],这些是独立的函数,我不能分解成更小的步骤。对于 AppClass::runSim(),更小的步骤可能是可能的。
c++ - How to control (i.e. abort) the current evaluation of a QScriptEngine
I evaluate JavaScript in my Qt application using QScriptEngine::evaluate(QString code)
. Let's say I evaluate a buggy piece of JavaScript which loops forever (or takes too long to wait for the result). How can I abort such an execution?
I want to control an evaluation via two buttons Run
and Abort
in a GUI. (But only one execution is allowed at a time.)
I thought of running the script via QtConcurrent::run
, keeping the QFuture
and calling cancel()
when the Abort
is was pressed. But the documentation says that I can't abort such executions. It seems like QFuture
only cancels after the current item in the job has been processed, i.e. when reducing or filtering a collection. But for QtConcurrent::run
this means that I can't use the future to abort its execution.
The other possibility I came up with was using a QThread
and calling quit()
, but there I have a similar problems: It only cancels the thread if / as soon as it is waiting in an event loop. But since my execution is a single function call, this is no option either.
QThread
also has terminate()
, but the documentation makes me worry a bit. Although my code itself doesn't involve mutexes, maybe QScriptEngine::evaluate
does behind the scenes?
Warning: This function is dangerous and its use is discouraged. The thread can be terminated at any point in its code path. Threads can be terminated while modifying data. There is no chance for the thread to clean up after itself, unlock any held mutexes, etc. In short, use this function only if absolutely necessary.
Is there another option I am missing, maybe some asynchronous evaluation feature?
c++ - QtConcurrent::run() 不能处理超过 5 个参数?
将具有 6 个或更多参数的函数传递给QtConcurrent::run()
. 当我将它们减少到 5 个参数时,我不再收到此错误。
这个虚拟代码为我重现了错误:
编译器错误是:
应该是这样吗?真的QtConcurrent::run()
最多限制为5个参数吗?
c++ - 如何卸载高度依赖于正确异常处理的计算量大的任务?
在我的 Qt 应用程序中,我必须执行一些计算量很大的任务,通常是从磁盘(单线程)加载大量数据集。任务中的代码严重依赖于适当的异常处理,并且严格来说是非 Qt。我使用 将这些任务从 GUI 线程中卸载QtConcurrent::run()
,以便显示进度条。但是,正如我从 Qt 文档中了解到的那样,我无法在 GUI 线程中捕获异常。我知道理论上这没有意义。但是,在实践中,由于进度条,我只使用线程。处理这种情况的最佳方法是什么?
编辑:我想强调的是,我不需要对卸载的工作进行细粒度控制。我真的只是卸载它以显示进度条。这可能是其他人也遇到过的情况。