版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38784098/article/details/77619426
1.新建一个按钮
QPushButton *browsebtn;
browsebtn = new QPushButton(this);
browsebtn->setText(QString::fromLocal8Bit("浏览"));
connect(browsebtn, SIGNAL(clicked(bool)), this, SLOT(openImage()));
2.实现openImage()
void Choicequestion::openImage()
{
QString fileName =QFileDialog::getOpenFileName(this,
QString::fromLocal8Bit("浏览"), QString(),
tr("Image Files (*.png *.jpg *.bmp)"));
//qDebug() << fileName;
if (!fileName.isEmpty())
{
lineF->setText(fileName);
}
//slotFile();
}