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

来源:互联网 发布:移动蜂窝数据是什么 编辑:程序博客网 时间:2024/06/15 12:29

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();}