简体   繁体   English

Qt 将 gui 小部件移动到 gui 线程

[英]Qt moving gui widget to gui thread

So Qt has to have all GUI applications running in the Main GUI thread.所以 Qt 必须让所有 GUI 应用程序都在主 GUI 线程中运行。 I have a non-gui cpp that initiates a QDialog, and when I try to interact with the Widget I get QObject::startTimer: Timers cannot be started from another thread .我有一个启动 QDialog 的非 gui cpp,当我尝试与 Widget 交互时,我得到QObject::startTimer: Timers cannot be started from another thread That is what led me to discover that I needed to move the widget to the main thread.这就是让我发现我需要将小部件移动到主线程的原因。 My question is how do I move no_id_wheel_screen to the main thread.我的问题是如何将no_id_wheel_screen移动到主线程。

cpp of my non-gui thread我的非gui线程的cpp

#include "gui_image_node.h"

gui_image_node::gui_image_node()
{

}

bool gui_image_node::init(int argc, char** argv)
{
    m_pThread = new QThread();

    m_no_id_wheel_screen = new no_id_wheel_screen;

    this->moveToThread(m_pThread);

    connect(m_pThread, &QThread::started, this, &gui_image_node::run);

    connect(m_no_id_wheel_screen, &no_id_wheel_screen::ReadyHollander, this, &gui_image_node::HolPub);

    hollander_pub = nh.advertise<std_msgs::String>("/hollander_chat", 1);

    hol_trigger = nh.subscribe("awaiting_hollander", 1, &gui_image_node::Hollander_Screen_trigger_callback, this);

    m_pThread->start();
    return true;
}
//Where I start the widget
void gui_image_node::Hollander_Screen_trigger_callback(const std_msgs::String::ConstPtr& msg)
{
    std::string steve = msg->data; 
    no_id_wheel_screen midscreen;
    midscreen.exec();
}

@Frank Osterfeld Had the right idea. @Frank Osterfeld 有正确的想法。 I just made another connection to MainWindow, then MainWindow executed my widget.我刚刚与 MainWindow 建立了另一个连接,然后 MainWindow 执行了我的小部件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM