昨天把Qtopia 2.2.0编译移植好了后,今天打算写一个hello world测试一下。拿到可执行文件后,下到板子上,加上-qws选项运行,结果直接Segmentation Fault。代码如下:
#include "qapplication.h"#include "qpushbutton.h"#include#include int main(int argc, char *argv[]){ QApplication app(argc,argv); QPushButton *hello = new QPushButton("Hello World.",0); //printf("hello.\n"); hello->resize(640,480); //hello->move(100,100); //printf("hello.move.\n"); hello->show(); app.setMainWidget(hello); //printf("hello.show.\n"); while(0) { printf("show...\n"); sleep(1); } return app.exec();}
检查代码,没问题,每一句后面加上printf语句,发现前面都没有问题,但只要执行到
return app.exec();
就会出现段错误。我在前面加上while(1)都没问题。上网google了一下,也有人遇到这问题,不过说法各不一样,主要都是说是编译器版本的问题,而我的环境不会有这个问题。在最后终于找到了原因:是编译选项需要加上宏QWS。出错前的编译命令为:
arm-hismall-linux-g++ -ohello hello.cpp -I$(HOME)/qt/qt-hisi-2.2.0/qtopia-free-2.2.0/qt2/include -I$(HOME)/qt/qt-hisi-2.2.0/qtopia-free-2.2.0/qt2/src/tools -lqte -L$(HOME)/qt/qt-hisi-2.2.0/qtopia-free-2.2.0/qtopia/lib -Wl,-rpath-link=/home/lzhong/qt/qt-hisi-2.2.0/build/lib结果编译链接都没有错误,但是一到板子上就是段错误。但加上-DQWS选项后就好了。