• 6120阅读
  • 6回复

初学qt,运行时总是提示段错误,请教各位高手! [复制链接]

上一主题 下一主题
离线kluv
 
只看楼主 倒序阅读 楼主  发表于: 2006-05-26
我要编一个读取图象的软件,这是打开文件的功能,也不知道对不对,但是编译通过后老说是段错误,我也没办法知道行不行了,以下是程序对代码,还请各位高手帮忙看一下,感觉qt好难哦,以前从来没有用过C++呀!!
#include<qapplication.h>
#include<qwidget.h>
#include<qfiledialog.h>
#include<qstring.h>
#include<qpushbutton.h>
#include<qlabel.h>
#include<qfont.h>


class OpenFile:public QWidget
{
  public:
    OpenFile();
private slots:
    void open();
private:
    QPushButton *b1;
    QFileDialog *fdialog;
  QString file;
};

OpenFile::OpenFile()
{
  setGeometry(500,500,400,300);
  b1=new QPushButton("open",this);
  b1->setGeometry(20,20,50,30);
  b1->setFont(QFont("Times",15,QFont::Bold));
  connect(b1,SIGNAL(clicked()),fdialog,SLOT(open()));  
}


void OpenFile::open()
{
  file=fdialog->getOpenFileName("/","*.bmp");

}

int main(int argc,char **argv)
{
    QApplication a(argc,argv);
  OpenFile file;
    a.setMainWidget(&file);
    file.show();
    a.exec();
}
[ 此贴被XChinux在2006-05-26 21:07重新编辑 ]
离线style
只看该作者 1楼 发表于: 2006-05-26
离线kluv
只看该作者 2楼 发表于: 2006-05-26
这是?????
没明白!!
离线shiroki

只看该作者 3楼 发表于: 2006-05-26
fdialog没有初始化
--
shiro is White
ki is tree
http://www.cuteqt.com
论坛 http://www.cuteqt.com/bbs
博客 http://www.cuteqt.com/blog
博客镜像: http://sites.cuteqt.com/cuteqt
Linux/Qt/嵌入式讨论群 http://qun.qq.com/air/5699823
离线kluv
只看该作者 4楼 发表于: 2006-05-27
要怎么样初始化呢??
完全是小白
离线style
只看该作者 5楼 发表于: 2006-05-27
---------------------
void OpenFile::open()
{
fdialog = new QFileDialog;
  file=fdialog->getOpenFileName("/","*.bmp");

}
离线chwoozy

只看该作者 6楼 发表于: 2006-05-30
同意楼上的。我试过,如果一个对象没有初始化就使用编译可能会通过,但是运行时总会遇到段错误的
快速回复
限100 字节
 
上一个 下一个