Qt-在vs2013 -打開文件對話框 讀取路徑 並顯示路徑

#include "CloudDetectionGUI.h"
#include"GBK.h"
#include <QDebug>
#include <QFileDialog> 
CloudDetectionGUI::CloudDetectionGUI(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	connect(ui.btnOpen1, SIGNAL(clicked()), this, SLOT(OnBtnOpen1()));
	connect(ui.btnSave1, SIGNAL(clicked()), this, SLOT(OnBtnSave1()));
}
int CloudDetectionGUI::OnBtnOpen1()
{
		//選擇要打開的文件
	QString filepath1 = QFileDialog::getExistingDirectory(
			this,//父窗口
			tr("選擇文件夾"));//標題caption
		if (filepath1.length() > 0)//爲空時表示取消操作
		{
			qDebug() << filepath1;
			string gbk_path = GBK::FromUnicode(filepath1);//獲取文件路徑
			ui.lineEditopen1->setText(GBK::ToUnicode(gbk_path));//顯示到文本框中

		}


		return 0;
}

int CloudDetectionGUI::OnBtnSave1()
{
	QString filepath1 = QFileDialog::getExistingDirectory(
		this,//父窗口
		tr("選擇文件夾"));//標題caption
	if (filepath1.length() > 0)//爲空時表示取消操作
	{
		qDebug() << filepath1;
		string gbk_path = GBK::FromUnicode(filepath1);//獲取文件路徑
		ui.lineEditsave1->setText(GBK::ToUnicode(gbk_path));//顯示到文本框中
	}
	return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章