• 7279阅读
  • 2回复

求助:QFileDialog类的错误问题(在线) [复制链接]

上一主题 下一主题
离线xiaoshumi
 
只看楼主 正序阅读 楼主  发表于: 2007-05-16
— 本帖被 XChinux 执行加亮操作(2008-07-19) —
错误信息:
[root@localhost test]# make
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -fno-default-inline -DNO_DEBUG -I/qt/qt-2.3.10/include -o test.o test.cpp
test.cpp: In member function `void Form1::openfile()':
test.cpp:47: no method `QFileDialog::getOpenFileName'
test.cpp:47: warning: unused variable `QString*filename'
make: *** [test.o] Error 1
[root@localhost test]#

为什么说QFileDialog中没有getOpenFileName方法啊?

下面贴出源码:

//*****************test.h********************//
#include <qvariant.h>
#include <qwidget.h>
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QPushButton;

class Form1 : public QWidget
{
    Q_OBJECT

public:
    Form1( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
    ~Form1();

    QPushButton* open;

public slots:
    void openfile();

};

//*****************test.cpp********************//

#include "test.h"

#include <qpushbutton.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qfiledialog.h>
#include <qstring.h>

/*
*  Constructs a Form1 which is a child of 'parent', with the
*  name 'name' and widget flags set to 'f'
*/
Form1::Form1( QWidget* parent,  const char* name, WFlags fl )
    : QWidget( parent, name, fl )
{
    if ( !name )
    setName( "Form1" );
    resize( 336, 221 );
    setCaption( tr( "Form1" ) );

    open = new QPushButton( this, "open" );
    open->setGeometry( QRect( 50, 90, 120, 35 ) );
    open->setText( tr( "open" ) );

    connect(open, SIGNAL(clicked()), SLOT(openfile()));
}

/* 
*  Destroys the object and frees any allocated resources
*/
Form1::~Form1()
{
    // no need to delete child widgets, Qt does it all for us
}

void Form1::openfile(){
    QString *filename=QFileDialog::getOpenFileName( QString::null, QString::null, this );
}
[ 此贴被XChinux在2008-07-19 20:06重新编辑 ]
离线xiaoshumi
只看该作者 2楼 发表于: 2007-05-16
呵呵,谢谢楼上的大哥!
版本是有点老,我作毕业设计,用上QT作个界面

不过,去掉指针还是同样的错误  啊!
唉,版本老了,大家都用QT4,出问题了都不好解决!
离线htyoung

只看该作者 1楼 发表于: 2007-05-16
QFileDialog::getOpenFileName 返回的是一个 QString 而不是一个指针 QString*

试试这样:
QString filename=QFileDialog::getOpenFileName( QString::null, QString::null, this );
你用的好像是 qt2.3.10, 有点老了,建议使用qt4.0以上
***
QT5
***
快速回复
限100 字节
 
上一个 下一个