qthread

Qt http get request always returns status code 0 in multi thread mode requests

独自空忆成欢 提交于 2020-03-05 22:36:57
问题 i have simple request method inside simple http client , that QRunnble worker is invoking all the returners of the request are status 0 , what more i spotted after few tests is, when i give the app to run with 1 thread that is only 1 url to process its working fine and i get status 200 . i suspect something in my http client code is worng and does not support multi thread mode here is my full httpclient code: this is the code of the request : #ifndef _HttpClient_ #define _HttpClient_ #include

Qt:QThread中直接使用QTimer,不封装QThread

六月ゝ 毕业季﹏ 提交于 2020-02-29 20:37:05
//工作类test moveToThread class Worker : public QObject { Q_OBJECT public: explicit Worker(QObject *parent = 0) : QObject(parent) {} signals: void doSomething(); public slots: void trigger() { qDebug() << "moveToThread Worker::trigger()"; emit doSomething(); } }; //主线程 void MainWindow::test_moveToThread() {//需要使用指针变量,否则退出该函数就析构了 QThread *thread = new QThread; Worker *work = new Worker; QTimer *timer = new QTimer; timer->setInterval(2000); timer->moveToThread(thread); work->moveToThread(thread); QObject::connect(thread, SIGNAL(started()), timer, SLOT(start())); QObject::connect(work, SIGNAL

Fixing Threads in PySide2

那年仲夏 提交于 2020-02-25 23:09:06
问题 I have programmed an application using PySide2 with some 800 lines of code and now when I want to show a variable in the progress bar it crashes after a short while without any warning. Silently. Just now it dawned on me that my whole approach to this GUI building is probably incorrect. Can this code be saved somehow so that it can via signals set this progress bar from inside the thread without the application crashing? EDIT: this minimal code works and crashes but needs a small ui file.

QThread与其他线程间相互通信

 ̄綄美尐妖づ 提交于 2020-02-19 18:19:41
转载请注明链接与作者huihui1988 QThread的用法其实比较简单,只需要派生一个QThread的子类,实现其中的run虚函数就大功告成, 用的时候创建该类的实例,调用它的start方法即可。但是run函数使用时有一点需要注意,即在其中不能创建任何gui线程(诸如新建一个QWidget或者QDialog)。如果要想通过新建的线程实现一个gui的功能,那么就需要通过使用线程间的通信来实现。这里使用一个简单的例子来理解一下 QThread中signal/slot的相关用法。 首先,派生一个QThread的子类 MyThread.h [cpp] view plain copy class MyThread: public QThread { Q_OBJECT public: MyThread(); void run(); signals: void send(QString s); }; void send(QString s)就是定义的信号 MyThread.cpp [cpp] view plain copy #include "MyThread.h" MyThread::MyThread() { } void MyThread::run() { while( true) { sleep(5); emit send( "This is the son thread"); /

doesn't update serial data using button click

浪尽此生 提交于 2020-01-30 09:01:06
问题 I have a problem with the gui data, my gui doesn't update a real-time value when I click the button. the first time i click my connect button it shows the correct value, but when i change the sensor position, it doesn't update the value. Where i miss the code, i try to solve the problem from the other similar question to this question, but still does not solve my problem here is my code class SerialReadThread(QThread): received_data = pyqtSignal(QByteArray, name="receivedData") def __init__

PyQt5 multi thread

左心房为你撑大大i 提交于 2020-01-30 05:29:05
问题 why the code doesn't work?? the video work file, when i tried to show a text in 2nd label it also show up.but If i want to change the value continuously like current time in the setText() what can i do? I am new in multi threading. import sys import cv2 from PyQt5.QtCore import QThread, pyqtSignal, Qt from PyQt5.QtGui import QPixmap, QImage from PyQt5.QtWidgets import QApplication, QWidget, QLabel import datetime class App(QWidget): def __init__(self): super().__init__() self.title = 'PyQt5

Qt开发——QThread多线程初探

南楼画角 提交于 2020-01-28 14:54:51
目录 效果: threaddlg.h threaddlg.cpp workthread.h workthread.cpp 效果: 开启多线程后,使用qDebug()打印观察输出; 停止多线程时,系统不会立即终止这个线程,线程何时终止取决于操作系统的调度,使用wait()等待线程阻塞直到超时退出 threaddlg.h #ifndef THREADDLG_H #define THREADDLG_H #include <QDialog> #include <QThread> #include <QPushButton> #include <QHBoxLayout> #include "workthread.h" static const int MAXSIZE = 1;//定义线程数量 class ThreadDlg : public QDialog { Q_OBJECT public: ThreadDlg(QWidget *parent = nullptr); ~ThreadDlg(); public slots: void slotStart();//开启线程 void slotStop();//结束线程 private: QPushButton *startBtn; QPushButton *stopBtn; QPushButton *quitBtn; QHBoxLayout

用Python来做一个屏幕录制工具

為{幸葍}努か 提交于 2020-01-27 03:23:04
一、写在前面 作为一名测试,有时候经常会遇到需要录屏记录自己操作,方便后续开发同学定位。以前都是用ScreenToGif来录屏制作成动态图,偶尔的机会看到python也能实现。那就赶紧学习下。 二、效果展示 三、知识串讲 这次要讲的东西可能比较多了,涉及到pyqt5 GUI软件的制作、QThread多线程的使用、Sikuli库的图形操作、win32库的模拟键盘操作、cv2库的写视频文件等。下面我们一点点来蚕食我这次写的代码。 1、GUI界面制作 这次我用的是现成的Pyqt5界面布局类,QVBoxLayout。这个类可以快速协助我完成按钮的垂直分布,而且按钮添加也更方便。 #Python学习交流群797877325 免费获取系统学习教程 button1 = QPushButton("自定义录屏") layout.addWidget(button1) 两行代码就完成了按钮的命名和添加。我之前玩qt时,用的都是qt的UI界面,对应生成的组件代码也比较复杂。因此,在开发一些少量按钮、简单布局时可以用QVBoxLayout类。如果喜欢水平布局,可以用QHBoxLayout类,使用方法是一样的。 另外,在按钮点击关联的功能函数,即work()方法时,如果想带参数,可以通过lambda匿名函数来实现。这 也是个小技巧。 # 不带参数 button1.clicked.connect(self

保持Qt GUI响应的几种方法

£可爱£侵袭症+ 提交于 2020-01-25 03:38:41
最开始使用Qt时就遇到过QT Gui失去响应的问题,我是用多线程的方式解决的,然而通常来说,多线程是会降低程序的运行速度。 之后,在使用 QSqlQuery::execBatch() 函数时,Qt Gui 又失去响应,虽然多线程可以解决,但是如果能用单线程很好解决的,最好不要用到多线程,因为多线程不仅容易拖慢程序的速度,编程及维护的难度也更大,能用简单方法解决的,就不要用复杂的方法。 于是我再次搜索资料,期望在解决方案的选择与解决步骤上,能够得到一个全面而又细致的总结。 Witold Wysota 的文章 https://doc.qt.io/archives/qq/qq27-responsive-guis.html#performinglongoperations 总结的非常不错。 Jason Lee的翻译: http://blog.csdn.net/jasonblog/article/details/5568589 所以本文是在此文基础上的部分翻译、理解与二次总结。总之,有删减,有补充,所以没写 '转' 字。 一、问题的来源与分析 首先,我们要知道 “为什么Qt Gui 会停止响应?”。简明扼要的说就是:长时间的密集处理或等待阻塞了Qt的事件循环,应用程序不能响应来自窗口系统的事件请求(《C++ Gui Qt4》 P135中有描述)。 那么多长算长呢?一秒钟算长,两秒钟太长。

QProgressBar update in QThread quitting crashes

混江龙づ霸主 提交于 2020-01-25 02:35:10
问题 I have the following code that works as expected. It updates the progress bar value in each for loop. The only issue I have is when I'm done and call emit ProcessUserRowsFinished() in the method OnProcessUserRowsStarted the program crashes. class UsersProcess: public QObject { Q_OBJECT public: UsersProcess(CTCore::DBConnect* db_context, UserSettingsMap user_settings_map); void SetProgressBar(QProgressBar *progress_bar); private: QProgressBar *progressBar; QSharedPointer<QList<CTCoreZen::User>