本来想显示的是“文本对话框”和”文件选择.jpg.png“,但是出现如下图的红色区域乱码。查询资料后,修改为字符串部分的代码为:
QStringList fileNames = QFileDialog::getOpenFileNames(this, QString("文件对话框"), "D:", QString("图片文件(*jpg *png);;文本文件(*txt)"));修改为:
QStringList fileNames = QFileDialog::getOpenFileNames(this, QString::fromLocal8Bit("文件对话框"), "D:", QString::fromLocal8Bit("图片文件(*jpg *png);;文本文件(*txt)"));
#include "myclass.h"
#include "qdialog.h"
#include "qfiledialog.h"
#include "qdebug.h"
#include "qtextcodec.h"
#include "qobject.h"
MyClass::MyClass(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
ui.label->hide();
connect(ui.showButton, SIGNAL(clicked()), this, SLOT(showButton()));
connect(ui.FileButton, SIGNAL(clicked()), this, SLOT(fileOpenButton()));
}
MyClass::~MyClass()
{
}
void MyClass::showButton()
{
//QDialog *dg = new QDialog(this);
//dg->show();
ui.label->show();
}
void MyClass::fileOpenButton()
{
QStringList fileNames = QFileDialog::getOpenFileNames(this, QString::fromLocal8Bit("文件对话框"), "D:", QString::fromLocal8Bit("图片文件(*jpg *png);;文本文件(*txt)"));
qDebug()<< "filenames:" << fileNames;
}
正确图: