问题标签 [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.
c++ - QException 的目的是什么?
在 Qt 5.0 - Qt 中引入了QException
类。
从这个类继承有什么好处?如果我们抛出一个不继承自 QException 类的类怎么办?
先感谢您!
c++ - Qt Concurrent 或 std::async 用于新代码?
我正在考虑运行异步代码的两个选项:Qt Concurrent和std::async
. 鉴于我正在使用 Qt 编写 GUI 应用程序,因此使用 Qt Concurrent 是有意义的。然而std::async
,似乎也不错,并且得到了所有主要编译器的支持。
我应该使用 Qt Concurrent 还是std::async
新代码?比较两者时我还应该寻找什么?
c++ - How to communicate a progressText from a QtConcurrent::run function (or similar) to a QFutureWatcher?
If I launch some function for asynchronous execution using QtConcurrent::run
, and am monitoring the returned future using a QFutureWatcher
, what if anything can I do in that asynchronously executing function to communicate some progress text back which will result in the QFutureWatcher
firing its progressTextChanged
signal?
ie what I want to do is something like:
However, big problem, the QtConcurrent::run documentation clearly states
Note that the QFuture returned by QtConcurrent::run() does not support canceling, pausing, or progress reporting. The QFuture returned can only be used to query for the running/finished status and the return value of the function.
So what's the simplest thing I can do which will get me something functionally equivalent to what the above is trying to do? Do I have to abandon QtConcurrent::run
? QFuture
? Both? (And go back to QThread
and queued connections?)
c++ - 如何获取非静态成员函数的地址以在 QtConcurrent 中使用?
我正在尝试在另一个线程中运行非静态成员函数。如果我走:
它提示
ISO C++ 禁止使用不合格或带括号的非静态成员函数的地址来形成指向成员函数的指针。
但如果我删除这个额外的参考符号:
它是这样的
无法将“PortManager::innerAsk”从“void (PortManager::)()”类型转换为“void* (PortManager::*)()”类型
在右侧添加什么以在左侧获得这些额外的星星(*)?
但是,即使我能到达那里,也总会有另一个错误;关于运行(T(*)()):
调用 'run(void* (PortManager::*&)()) 没有匹配的函数
我很难理解这个参考是如何到达那里的......
c++ - 将 QtConcurrent 用于单例
我在自己的项目中使用线程安全的 QObject 单例,我想知道使用 QtConcurrent 而不是 QMutex'es 和 QThread's 创建它们是否正确。
这是我如何编写单例代码。
这比以下更好吗?
或者,还有其他更好的方法吗?
谢谢你。
注意:我正在单独处理共享实例销毁。
编辑:我希望共享实例位于主线程中。
c++ - QtConcurrency::映射有成员函数
如何QtConcurrent::mapped
将成员函数用作运算符?目前我正在使用一个可调用对象(这是一个丑陋的解决方案):
还尝试传递 lambda 表达式,但编译器说result_type
lambda 中没有定义。这适用于QtConcurrent::map
因为map
不需要result_type
. 所以如果我可以typedef
在 lambda 中添加一个它应该可以工作......
c++ - Qt并发运行,通过引用传值,但是内存地址不一样?
我QtConcurrent::run
用来运行一个函数,并通过引用传递值,但是值的内存地址不同。
但是如果我通过指针传递值,地址是一样的!我想不通。我错过了什么吗?
这是代码。
输出:
c++ - 使用“无限”循环正确处理 QtConcurrent
我正在做一个程序,用户可以在其中看到来自摄像机的视频并记录下来。我正在使用 QtMEL 库来获取摄像头馈送和记录。当相机启动时,它会调用一个带有 QTconcurrent::run() 的函数来抓取帧。在此函数内部有一个无限循环,用于检查摄像头馈送是否已关闭,如果是,则退出循环。像这样的东西:
如果用户关闭相机(停止抓帧并结束线程)然后程序存在,一切都很好。问题是当用户退出程序而相机仍然打开时。如果发生这种情况,进程将永远运行或引发分段错误错误。
我已经搜索了文档并根据它:
请注意,QtConcurrent::run() 返回的 QFuture 不支持取消、暂停或进度报告。返回的 QFuture 只能用于查询函数的运行/结束状态和返回值。
我想出了一个解决这个问题的方法,我不知道它是否是最好的,我想从比我更有经验的人那里得到更多的见解。
基本上我重新实现了这样的closeEvent:
在插槽上:
也许我很天真,但在我看来,有一个更好的解决方案。有经验的人能帮帮我吗?
在此先感谢您的时间。
qt - 阻塞 QFuture.result() 或 QFutureWatcher.waitForFinished();
所以我一直在使用 QtConcurrent::run 一段时间,它很棒。但是现在我需要该函数来返回一个对象。因此我使用伪代码
然后我遍历 myObject。问题是这会阻塞,例如我的主 GUI 没有响应。这就是我开始使用 QtConcurrent::run 的全部原因
因此,让我的 GUI 执行 QtConcurrent::run 并取回对象但不阻塞的推荐方法是什么?我想到了信号来自 QtConcurrent::run 的信号和插槽,但这意味着它将来自不同的线程,我读到不推荐这样做。
谢谢你的时间。
c++ - QtConcurrent 参数数量错误
我有一个 QMainWindow 类。
我有 SqlStorage 类来对数据库进行操作。
在 insertVector() 方法中,我尝试异步写入数据库。
但是当我尝试编译时,我有一个错误:“术语不评估为带 1 个参数的函数”。
我的问题在哪里?