PDA

View Full Version : I want to open a QFileDialog, but this code does not open it.



rezas1000
25th September 2014, 06:53
Hello, I want to open a QFileDialog, but this code does not open it.why? thank you.

#include <QtWidgets>
#include "widget.h"
widget::widget()
{
text=new QTextEdit;
resize(250,250);
setCentralWidget(text);
createaction();
createmenu();
createStatusBar();
}
void widget::createmenu()
{
filemenu=menuBar()->addMenu(tr("File"));
filemenu->addAction(newact);
}
void widget::createaction()
{
newact=new QAction(tr("&Open"),this);
newact->setShortcut(QKeySequence::Open);
newact->setStatusTip("Open a new file");
connect(newact,SIGNAL(triggered()),this,SLOT(openf ile()));
}
void widget::createStatusBar()
{
statusBar()->showMessage(tr("Ready"));
}
void widget::openfile()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open File"), QDir::currentPath());
}
when I press the action Open, it does not open a QFileDialog :confused:

stampede
25th September 2014, 07:23
Is "openfile" declared as SLOT ? Does your class have a Q_OBJECT macro ?

rezas1000
25th September 2014, 07:50
thank you very much.I had forgotten the Q_OBJECT.!!! I used the Q_OBJECT and now,it opens the QFileDialog.