C++ starts the thread to display the UI interface of Qt

Ways to start threads:

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

MissionDispatchDisplay function:

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();
}

Guess you like

Origin blog.csdn.net/weixin_43795921/article/details/115340955