#include <QApplication>
#include <QFileDialog>
class Tester : public QWidget
{
public :
void openFile ()
{
qDebug ( filename.toAscii () ) ;
}
}
void openFiles ()
{
QStringList filenames = QFileDialog::getOpenFileNames ( this, tr ( "Open Document" ) , QDir::currentPath () , tr ( "Documents (*.doc);;All files (*.*)" ) ) ;
qDebug ( filenames.join ( "," ) .toAscii () ) ;
}
}
void openDir ()
{
QString dirname = QFileDialog::getExistingDirectory ( this, tr ( "Select a Directory" ) , QDir::currentPath () ) ;
if ( !dirname.isNull () )
{
qDebug ( dirname.toAscii () ) ;
}
}
void saveFile ()
{
QString filename = QFileDialog::getSaveFileName ( this, tr ( "Save Document" ) , QDir::currentPath () , tr ( "Documents (*.doc)" ) ) ;
if ( !filename.isNull () )
{
qDebug ( filename.toAscii () ) ;
}
}
} ;
int main ( int argc, char **argv )
{
QApplication app ( argc, argv ) ;
Tester t;
t.openFile () ;
t.openFiles () ;
t.openDir () ;
t.saveFile () ;
return 0 ;
}
#include <QFileDialog>
class Tester : public QWidget
{
public :
void openFile ()
{
QFileDialog::getOpenFileName( this, tr("Open Document"), QDir::currentPath(), tr("Document files (*.doc *.rtf);;All files (*.*)"), 0, QFileDialog::DontUseNativeDialog );
QString filename = QFileDialog::getOpenFileName(this, tr("Open Document"), QDir::currentPath(), tr("Document files (*.doc *.rtf);;All files (*.*)") );
if( !filename.isNull() )
{qDebug ( filename.toAscii () ) ;
}
}
void openFiles ()
{
QStringList filenames = QFileDialog::getOpenFileNames ( this, tr ( "Open Document" ) , QDir::currentPath () , tr ( "Documents (*.doc);;All files (*.*)" ) ) ;
if( !filenames.isEmpty() )
{qDebug ( filenames.join ( "," ) .toAscii () ) ;
}
}
void openDir ()
{
QString dirname = QFileDialog::getExistingDirectory ( this, tr ( "Select a Directory" ) , QDir::currentPath () ) ;
if ( !dirname.isNull () )
{
qDebug ( dirname.toAscii () ) ;
}
}
void saveFile ()
{
QString filename = QFileDialog::getSaveFileName ( this, tr ( "Save Document" ) , QDir::currentPath () , tr ( "Documents (*.doc)" ) ) ;
if ( !filename.isNull () )
{
qDebug ( filename.toAscii () ) ;
}
}
} ;
int main ( int argc, char **argv )
{
QApplication app ( argc, argv ) ;
Tester t;
t.openFile () ;
t.openFiles () ;
t.openDir () ;
t.saveFile () ;
return 0 ;
}