当前位置: 首页 > news >正文

网站标题字数手机如何制作网站教程

网站标题字数,手机如何制作网站教程,wordpress内链添加位置,asp 网站权限设计文章目录 connent函数第五个参数的作用自动连接(Qt::AutoConnection)直接连接(Qt::DirectConnection - 同步)同线程不同线程 队列连接(Qt::QueuedConnection - 异步)同一线程不同线程 锁定队列连接(Qt::BlockingQueuedConnection) connent函数第五个参数的作用 connect(const … 文章目录 connent函数第五个参数的作用自动连接(Qt::AutoConnection)直接连接(Qt::DirectConnection - 同步)同线程不同线程 队列连接(Qt::QueuedConnection - 异步)同一线程不同线程 锁定队列连接(Qt::BlockingQueuedConnection) connent函数第五个参数的作用 connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type Qt::AutoConnection)第五个参数代表槽函数在哪个线程中执行 自动连接(Qt::AutoConnection)默认的连接方式如果信号与槽也就是发送者与接受者在同一线程等同于直接连接如果发送者与接收者处在不同线程等同于队列连接。 直接连接(Qt::DirectConnection)当信号发射时槽函数立即直接调用。无论槽函数所属对象在哪个线程槽函数总在发送者所在线程执行即槽函数和信号发送者在同一线程。 队列连接(Qt::QueuedConnection)当Thread1触发信号后信号会在处理完前面的任务后再调用相应的槽函数槽函数在接收者线程中执行Thread1立即会执行下面任务无需等待接收者线程执行槽函数完毕。 锁定队列连接(Qt::BlockingQueuedConnection)槽函数的调用时机与Qt::QueuedConnection一致不过发送完信号后发送者所在线程会阻塞直到槽函数运行完。接收者和发送者绝对不能在一个线程否则程序会死锁。在多线程间需要同步的场合可能需要这个。 自动连接(Qt::AutoConnection) 自动连接(Qt::AutoConnection)默认的连接方式如果信号与槽也就是发送者与接受者在同一线程等同于直接连接如果发送者与接收者处在不同线程等同于队列连接。 直接连接(Qt::DirectConnection - 同步) 同线程 mainwindow.cpp主线程 #include mainwindow.h #include ui_mainwindow.h #include QDebug #include QThreadMainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow) {ui-setupUi(this);connect(this,SIGNAL(sig()),this,SLOT(slot()),Qt::DirectConnection);emit sig();for(int i0; i10;i){qDebug() i;} }MainWindow::~MainWindow() {delete ui; }void MainWindow::slot() {qDebug()执行槽函数; }mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H#include QMainWindow #include thread1.hnamespace Ui { class MainWindow; }class MainWindow : public QMainWindow {Q_OBJECTpublic:explicit MainWindow(QWidget *parent 0);~MainWindow();private:Ui::MainWindow *ui; private slots:void slot(); signals:void sig(); };#endif // MAINWINDOW_H结论 发射信号后立马执行槽函数。 不同线程 mainwindow.cpp #include mainwindow.h #include ui_mainwindow.h #include QDebugMainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow) {ui-setupUi(this);qDebug()u8主线程IDQThread::currentThreadId();connect(m_thread1,SIGNAL(sigThread1()),this,SLOT(slot()),Qt::DirectConnection);m_thread1.start(); } MainWindow::~MainWindow() {delete ui; } void MainWindow::slot() {qDebug()u8执行槽函数---线程IDQThread::currentThreadId(); }mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H#include QMainWindow #include thread1.hnamespace Ui { class MainWindow; }class MainWindow : public QMainWindow {Q_OBJECTpublic:explicit MainWindow(QWidget *parent 0);~MainWindow();private:Ui::MainWindow *ui;Thread1 m_thread1;private slots:void slot();// 在主函数中定义需要调用的槽函数 };#endif // MAINWINDOW_Hthread1.cpp #include thread1.h #include QDebugThread1::Thread1(QThread *parent): QThread(parent) {}void Thread1::run() {qDebug()u8Thread1线程IDQThread::currentThreadId();emit sigThread1();for(int i0;i10;i){qDebug()i;} }thread1.h #ifndef THREAD1_H #define THREAD1_H#include QThreadclass Thread1 : public QThread {Q_OBJECT public:explicit Thread1(QThread *parent 0);protected:virtual void run();signals:void sigThread1(); }; #endif // THREAD1_H结论 可以看出emit发射信号后立马执行槽函数没有任何等待并且槽函数执行在Thread1线程中 队列连接(Qt::QueuedConnection - 异步) 同一线程 mainwindow.cpp #include mainwindow.h #include ui_mainwindow.h #include QDebug #include QThreadMainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow) {ui-setupUi(this);connect(this,SIGNAL(sig()),this,SLOT(slot()),Qt::QueuedConnection);emit sig();for(int i0; i10;i){qDebug()i;} }MainWindow::~MainWindow() {delete ui; }void MainWindow::slot() {qDebug()u8执行槽函数; }mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H#include QMainWindow #include thread1.hnamespace Ui { class MainWindow; }class MainWindow : public QMainWindow {Q_OBJECTpublic:explicit MainWindow(QWidget *parent 0);~MainWindow();private:Ui::MainWindow *ui;private slots:void slot(); signals:void sig(); };#endif // MAINWINDOW_H结论 可以看到先执行完for循环先把自己的事情处理完当空闲后再执行槽函数。 不同线程 mainwindow.cpp #include mainwindow.h #include ui_mainwindow.h #include QDebugMainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow) {ui-setupUi(this);qDebug()u8主线程IDQThread::currentThreadId();connect(m_thread1,SIGNAL(sigThread1()),this,SLOT(slot()),Qt::QueuedConnection);m_thread1.start(); }MainWindow::~MainWindow() {delete ui; }void MainWindow::slot() {qDebug()u8执行槽函数---线程IDQThread::currentThreadId(); }mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H#include QMainWindow #include thread1.hnamespace Ui { class MainWindow; }class MainWindow : public QMainWindow {Q_OBJECTpublic:explicit MainWindow(QWidget *parent 0);~MainWindow();private:Ui::MainWindow *ui;Thread1 m_thread1;private slots:void slot();}; #endif // MAINWINDOW_Hthread1.cpp #include thread1.h #include QDebugThread1::Thread1(QThread *parent): QThread(parent) {} void Thread1::run() {qDebug()u8Thread1线程IDQThread::currentThreadId();emit sigThread1();for(int i0;i10000;i) //此处为10000次加长时间以便更清楚的观察现象{qDebug()i;} }thread1.h #ifndef THREAD1_H #define THREAD1_H#include QThreadclass Thread1 : public QThread {Q_OBJECT public:explicit Thread1(QThread *parent 0);protected:virtual void run();signals:void sigThread1(); };#endif // THREAD1_H结论 可以看出thread1线程发送信号后thread1接着做自己的事主线程同样接着做自己的事。当主线程空闲时再执行槽函数槽函数运行在主线程中。 锁定队列连接(Qt::BlockingQueuedConnection) 代码参考上面的将Qt::QueuedConnection改为Qt::BlockingQueuedConnection即可。可以看到规律同Qt::QueuedConnection不过thread1线程发送完信号后会阻塞直到主线程的槽函数返回thread1线程才会继续向下执行。
http://www.w-s-a.com/news/741457/

相关文章:

  • 农业信息网站建设意义淘宝官网首页网址
  • 重庆网站设计公司价格贵阳网站建设app开发
  • dw做网站怎么换图片编写网页所用的语言是
  • 外贸网站收录工具个人网站的备案
  • 正规的网站建设工作室海外高延迟服务器做网站
  • 网站设计确认函合肥做网站维护的公司
  • 小说网站推荐网站开发语言怎么查
  • 网页制作基础教程慕课版电子版那种登录才能查看的网站怎么做优化
  • 制作网站用的域名网站域名注册信息查询
  • 公司域名查询官方网站女教师遭网课入侵直播录屏曝
  • 网站开发社交网络功能的作用腾讯公司网站
  • 网站建设需要微信账号和密码网站建设工作汇报
  • 国家城乡住房和建设部网站西安私人网站
  • 天津高端网站定制seo实战教程
  • 网站文章怎么做才能被快速收录网站备案核验系统
  • 子网站建设方案l建设银行网站
  • 免费看舆情网站网站备案用户名忘了怎么办
  • 地方门户网站的分类网站的方案
  • 沧州哪里做网站网站的建设是什么
  • 设计公司海报秦皇岛seo网站推广
  • 网站导航规划wordpress做漫画
  • jsp体育用品网站建设wordpress 10万篇文章
  • 沈阳做微信和网站的公司网站在线支付接口
  • 重庆整合网络营销百度seo快速提升排名
  • 设计师网站外网百度分析工具
  • 旅游网站建设技术解决方案wordpress主题安装后找不到
  • 网站图片文字排版错误管理系统界面设计
  • 网站建设 台州广州惠科互联网技术有限公司
  • 网站页面尺寸大小四川鸿业建设集团网站
  • 做女朋友的网站局网站建设方案word