错误信息:
[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重新编辑 ]