【发布时间】:2015-09-04 13:47:18
【问题描述】:
在这段代码中,Qt 部分 (fun1()) 总是崩溃。它写道:
terminate called without an active exception
Aborted (core dumped)
应该有什么问题?当我在 main 中调用 Qt 的东西时,我不使用线程它工作得很好,但我需要调用另一个函数并使用线程(fun2()只是为了说明) 我的代码在这里:
#include "../common/main_window.hpp"
#include <QtGui/QApplication>
#include <QtGui>
#include <thread>
#include <iostream>
int argc_;
char **argv_;
void fun1()
{
QApplication a(argc_,argv_);
MainWindow w;
w.show();
a.exec();
}
void fun2()
{
std::cout << "Print something" << std::endl;
}
int main(int argc, char **argv)
{
//argc_ = malloc((1)*sizeof(char*));
argc_= argc;
argv_= argv;
std::thread first(fun1);
std::thread second(fun2);
return 0;
}
【问题讨论】:
-
我有一个问题。我想在我的项目中使用线程(不是 QThread)。我添加了 refrence #include
,但我的 Qt 类不知道 std::thread。我该如何解决?
标签: c++ multithreading qt c++11