实现文件图片浏览功能,并把路径输入文本框

版权声明:本文为博主原创文章,未经博主允许不得转载。 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();
}




猜你喜欢

转载自blog.csdn.net/qq_38784098/article/details/77619426