不 行啊,哥们,还是没有动静呢,没有报错同时。
[C++] 纯文本查看 复制代码 #include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSettings>
#include <QString>
#include <QDebug>
#include <QDir>
#pragma execution_character_set("utf-8");
#include <QRegularExpression>
#include <QFile>
#include <QTextStream>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked() //读取INI,设置到Edit1 2 3 控件上!
{
QSettings *configIniRead = new QSettings("config.ini", QSettings::IniFormat);
//将读取到的ini文件保存在QString中,先取值,然后通过toString()函数转换成QString类型
QString jianzhi = configIniRead->value("/ip/first").toString();
ui->Edit3->setText(jianzhi);
// QString portResult = configIniRead->value("/port/open").toString();
// ui->Edit2->setText(portResult);
// qDebug() << ipResult; //打印得到的结果
// qDebug() << portResult;
//读入入完成后删除指针
delete configIniRead;
//获取应用程序可执行文件所在的目录
qDebug()<<"current applicationDirPath: "<<QCoreApplication::applicationDirPath();
QString strPath = QCoreApplication::applicationDirPath();
QDir dir(strPath);
bool bSuccess = dir.cdUp();
if (bSuccess == true) {
strPath = dir.path() + "/";
}
qDebug()<<"上一级目录是:"<<strPath;
}
void MainWindow::on_InsertNewItem_clicked()//插入新项到列表中OK了!
{
QListWidgetItem * aItem= new QListWidgetItem("CC");
ui->listWidget->insertItem(ui->listWidget->currentRow(),aItem);
}
void MainWindow::on_LoadtxtToList_clicked()
{
ui->listWidget->clear();
QFile dataFile("c:\1.txt");
if (dataFile.open(QFile::ReadOnly|QIODevice::Text))
{
QTextStream data(&dataFile);
QStringList fonts;
QString line;
while (!data.atEnd()) { //逐行读取文本,并去除每行的回车
line = data.readLine();
line.remove('\n');
fonts.append(line);
}
ui->listWidget->addItems(fonts); //把各行添加到listwidget
}
// QFile file("c:\1.txt");
// if (file.open(QIODevice::ReadOnly | QIODevice::Text))
// {
// while (!file.atEnd())
// {
// QByteArray line = file.readLine();
// QString str(line);
// QRegularExpression re("(?<=^\\[).*(?=\\])");
// QRegularExpression re("(?<=NoteName=).*");
// QRegularExpressionMatch match = re.match(str);
// if (match.hasMatch())
// {
// QString matched = match.captured(0);
// ui->comboBox->addItem(matched);
// }
// QListWidgetItem * aItem= new QListWidgetItem(str);
// ui->listWidget->insertItem(ui->listWidget->currentRow(),aItem);
}
// file.close();
|