• 4353阅读
  • 8回复

[提问]段错误 [复制链接]

上一主题 下一主题
离线hcfalan
 

只看楼主 倒序阅读 楼主  发表于: 2013-04-13
关键词: 段错误调试
平台 windows 7 + mingw gcc 4.4 + qt 4.8.4。
我的程序相当简单,使用mingw32-make生成的debug可执行文件可以运行正常。gdb一调试就出错误界面可以出来,但是按钮上的“hello!"不见了。小弟QT新手,求指点。代码如下:

#include <QApplication>
#include <QPushButton>


int main(int argc, char* argv[])
{
    QApplication app(argc, argv);


    QPushButton* mw = new QPushButton();
    mw->setText("hello!");
        mw->show();


    return app.exec();
}


gdb调试的输出:

I:\qt_rio\sample\debug>gdb sample.exe
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32"...
(gdb) r
Starting program: I:\qt_rio\sample\debug/sample.exe
[New thread 2184.0x1464]
[New thread 2184.0xb24]


Program received signal SIGSEGV, Segmentation fault.
0x0d1d29b5 in winhafnt!UninstallDetours ()
   from C:\Windows\system32\winhafnt.dll
(gdb) q
The program is running.  Exit anyway? (y or n) y
离线jdwx

只看该作者 1楼 发表于: 2013-04-13
  1. #include <QApplication>
  2. #include <QPushButton>
  3. int main(int argc, char* argv[])
  4. {
  5.     QApplication app(argc, argv);
  6.     QPushButton mw ;
  7.     mw.setText("hello!");
  8.     mw.show();
  9.     return app.exec();
  10. }

改成这样吧,重新qmake,make。
发帖时要说明:操作系统、Qt版本、编译器,这样能更快的得到回复。
离线hcfalan

只看该作者 2楼 发表于: 2013-04-13
代码已经按你说的改了。重新make和编译了,还是不行,快疯了:
rmdir /q /s debug
qmake sample.pro
mingw32-make debug
cd debug

I:\qt_rio\sample\debug>gdb sample.exe
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32"...
(gdb) r
Starting program: I:\qt_rio\sample\debug/sample.exe
[New thread 7072.0x1170]
[New thread 7072.0x13f4]

Program received signal SIGSEGV, Segmentation fault.
0x0d5429b5 in winhafnt!UninstallDetours ()
   from C:\Windows\system32\winhafnt.dll
(gdb) q
The program is running.  Exit anyway? (y or n) y
离线jdwx

只看该作者 3楼 发表于: 2013-04-13
回 2楼(hcfalan) 的帖子
用QtCreator新建一个GUI程序,再用QtCreator调试看看。

发帖时要说明:操作系统、Qt版本、编译器,这样能更快的得到回复。
离线hcfalan

只看该作者 4楼 发表于: 2013-04-13
回 3楼(jdwx) 的帖子
一样的,还是段错误。
离线彩阳

只看该作者 5楼 发表于: 2013-04-13
MinGW4.4中的gdb不完善,不建议使用。
上海Qt开发联盟,热忱地欢迎你的加入!
离线hcfalan

只看该作者 6楼 发表于: 2013-04-15
回 5楼(彩阳) 的帖子
那我得用什么调试工具啊??
离线彩阳

只看该作者 7楼 发表于: 2013-04-15
换Qt5试试,它的MinGW自带的是4.7,我觉得比4.4的要好一些。
上海Qt开发联盟,热忱地欢迎你的加入!
离线hcfalan

只看该作者 8楼 发表于: 2013-04-18
回 7楼(彩阳) 的帖子
谢谢大家的指点,放弃了MinGW,使用VS2010,用CDB调试(Debugging Tools for Windows x86)可以了。
快速回复
限100 字节
 
上一个 下一个