Hello, I want to open a QFileDialog, but this code does not open it.why? thank you.
#include <QtWidgets>
#include "widget.h"
widget::widget()
{
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->setStatusTip("Open a new file");
connect(newact,SIGNAL(triggered()),this,SLOT(openfile()));
}
void widget::createStatusBar()
{
statusBar()->showMessage(tr("Ready"));
}
void widget::openfile()
{
tr
("Open File"),
QDir::currentPath());
}
#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(openfile()));
}
void widget::createStatusBar()
{
statusBar()->showMessage(tr("Ready"));
}
void widget::openfile()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open File"), QDir::currentPath());
}
To copy to clipboard, switch view to plain text mode
when I press the action Open, it does not open a QFileDialog
Bookmarks