당신은 같은 pthread와에서의 QApplication을 시작할 수 있습니다 //appthread.cpp
#include <iostream>
#include "appthread.h"
int main(int argc, char *argv[]) {
InputArgs args = {argc, argv};
StartAppThread(args);
sleep(10);
return 0;
}
//appthread.h
struct InputArgs{
int argc;
char **argv;
};
void StartAppThread(InputArgs &);
//main.cpp
아래
#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
#include "appthread.h"
#include <pthread.h>
void *StartQAppThread(void *threadArg) {
InputArgs *args = (struct InputArgs*) threadArg;
QApplication app(args->argc, args->argv);
QMainWindow w;
w.show();
w.setCentralWidget(new QPushButton("NewButton"));
app.exec();
pthread_exit(NULL);
}
void StartAppThread(InputArgs &args) {
pthread_t thread1;
int rc = pthread_create(&thread1, NULL, StartQAppThread, (void*)&args);
}
당신이 맞을지도 모른다고 생각합니다. VestniK - 실제로 GUI가 실행되는 동안 OS가 강제로 다른 GUI를 드래그하여 GUI를 다시 그리지 않으면 실제로 update() 호출을 서비스하지 않는 것 같습니다. – rcv
이 대답은 다른 문제를 해결하는 데 유용하지만 QMainWindow 객체를 다른 스레드에서 주 스레드로 이동하는 동안 QObject :: moveToThread를 받았다 : 위젯을 새 스레드로 이동할 수 없음 – ASten