1、打开文件对话框
//打开文件对话框
QString fileName = QFileDialog::getOpenFileName(this, tr("打开"));
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
QMessageBox::StandardButton btnValue = QMessageBox::information(this, tr("提示"), tr("打开失败!"));
2、读取文本文件
//创建文本流
QTextStream stream(&file);
QString str=stream.readLine();
while (!stream.atEnd())
{
//逐行读取
QString str=stream.readLine();
}
3、按指定符号分割字符串
QStringList list = str.split(",");
4、消息提示对话框
QMessageBox::StandardButton btnValue = QMessageBox::information(this, tr("提示"), tr("打开失败!"));
QMessageBox msgBox;
msgBox.setText("账号或密码错误");
msgBox.exec();
5、中文字符无法正常显示问题,在头文件中添加如下代码:
#pragma execution_character_set("UTF-8")
6、QT数据库创建表语句
QSqlQuery query;
QString str = "create table student(userID int primary key,userPwd varchar(50));";
if (query.exec(str) == false)
qDebug() << "model::CreateTable():" << query.lastError();
7、QT数据库插入数据语句
QSqlQuery query;
QString str = QString("INSERT INTO student VALUES('%1','%2')").arg(ID).arg(Pwd);
if (!query.exec(str))
{
qDebug() << "model::insertTb():" << query.lastError().text();
}
8、vector定义
std::vector<Pointp> p;