这是我的源代码, super 简单:
#include<QApplication>
#include<QLabel>
int main(int argc,char* argv[])
{
QApplication app(argc,argv);
QLabel *label=new QLabel("Hello world");
label->show();
return app.exec();
}
当我构建它时,一切都很好。但是当我尝试运行它时,它立即停止,并告诉我“*.exe 已经停止。关闭它或调试它。”。
所以我尝试调试它。过了一会儿,它抛出一条消息:
The inferior stopped because it received a signal from the operating system
SINAL NAME: SIGSEGV
SIGNAL MEANING: segmentation default
我在 google、stackoverflow 和 wikipedia 上查了很多资料。很多人说是指针使用不当造成的。但是我找不到问题出在哪里。请帮忙。
顺便说一下,我使用的是 win7,我已经在 qt 4.8.5 和 qt 5.4.0 上试用过了。 编译器和调试器都很好(至少 qt creator 没有显示错误)。
我应该重新安装 Qt 还是其他?
这是调试器为我指出的错误代码(在 qatomic_i386.h 中):
inline bool QBasicAtomicInt::deref()
{
unsigned char ret;
asm volatile("lock\n"
"decl %0\n"
"setne %1"
: "=m" (_q_value), "=qm" (ret)
: "m" (_q_value)
: "memory"); //this is the wrong code the debugger point out for me
return ret != 0;
}
qstring.h 中的另一行:
inline QString::~QString() { if (!d->ref.deref()) free(d); }
这些都是错误的信息。谢谢。
*****************代码更改***但一样******
#include<QApplication>
#include<QLabel>
#include<QDialog>
int main(int argc,char* argv[])
{
QApplication app(argc,argv);
QDialog* dialog=new QDialog;
QLabel* label=new QLabel(dialog);
label->setText("Hello world");
dialog->show();
//label->show(); it's the same with or without this
return app.exec();
}
************更多变化但相同*********
#include<QApplication>
#include<QLabel>
#include<QDialog>
int main(int argc,char* argv[])
{
QApplication app(argc,argv);
QDialog dialog;
QLabel label(&dialog);
label.setText("Hello world");
dialog.show();
//label->show();
return app.exec();
}
最佳答案
请检查您的 .pro 文件,您没有尝试使用控制台应用程序,您必须使用 qwidet 应用程序。:
#-------------------------------------------------
#
# Project created by QtCreator 2015-05-04T11:12:27
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = testapp
TEMPLATE = app
SOURCES += main.cpp
应用程序使用您的代码对我来说效果很好,它运行 procces_stub.exe 命令,然后在窗口上显示标签...
关于c++ - 在使用 Qt Creator 创建一个非常简单的项目时卡在 Qt 中的 "segmentation fault",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29939698/