C++开启线程来进行Qt的UI界面显示

开启线程的方式:

std::thread ui_thread(&MissionDispatcher::MissionDispatchDisplay, this);
ui_thread.detach();
std::this_thread::sleep_for(std::chrono::milliseconds(1000));

MissionDispatchDisplay函数:

int MissionDispatcher::MissionDispatchDisplay() {
    
    
  int argc = 1;
  char program_name[]{
    
    "/home/bingo/Code/ugv_ws/devel/lib/ab/mission_dispatch"};
  char** argv;
  argv = (char**)malloc(sizeof(char*) * 1);
  argv[0] = program_name;
  QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

  QGuiApplication app(argc, argv);

  QQmlApplicationEngine engine;
  engine.load(QUrl(QStringLiteral("qrc:/mission_dispatch.qml")));
  if (engine.rootObjects().isEmpty()) return -1;

  return app.exec();
}

猜你喜欢

转载自blog.csdn.net/weixin_43795921/article/details/115340955