qt连接mysql数据库以及txt文本的复制操作
来源:互联网 发布:最新网络名词英文 编辑:程序博客网 时间:2024/04/27 03:07
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QDialog>
#include <QPalette>
#include <QButtonGroup>
#include <QMessageBox>
#include <QSqlTableModel>
#include <QSqlRecord>
#include <QTime>
#include <QMessageBox>
#include <QButtonGroup>
#include <QSqlQuery>
#include <string>
using namespace std;
#include <iostream>
#include <fstream>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("test");
db.setUserName("root");
db.setPassword("123456");
db.open();
model=new QSqlTableModel(this);
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QSqlQuery query;
query.exec("SELECT * FROM students ORDER BY id ASC");
model->setTable("students");
model->select();
while (query.next())
{
//依次获取表中第五列数据
int rowNum = model->rowCount(); // 获得表的行数
qDebug()<<"rowNum"<<rowNum<<endl;
QString txtph = query.value(4).toString();//query.value()的参数只能是index(第五列的数据)
qDebug()<<"txtph"<<txtph<<endl;
QByteArray aByteArray = txtph.toLatin1();//先把转化为QByteArray的结果存储起来
const char* txtph2 = aByteArray.data();//再调用data()或constData()
//获取每个txt文本路径,并全部复制到2.txt中(txt文本的复制操作)
ifstream myfile(txtph2);
ofstream outfile("D:\\VS\\born\\2.txt", ofstream::app);
string temp;
if (!myfile.is_open()) {
cout << "未成功打开文件" << endl;
}
// while (getline(myfile, temp,'\n')) {
while (getline(myfile, temp)) {
outfile << temp ;
// outfile << temp ;
}
outfile<<endl;
myfile.close();
// if(pFileIn[0]==NULL || pFileIn[1]==NULL || pFileOut==NULL) return 1;
// for(int i=0;i<2;i++)
// {
// while(!feof(pFileIn[i]))
// {
// ch=fgetc(pFileIn[i]);
// fputc(ch,pFileOut);
// }
// fclose(pFileIn[i]);
// }
}
}
0 0
- qt连接mysql数据库以及txt文本的复制操作
- Python连接以及操作MySQL数据库详解
- Python连接以及操作MySQL数据库详解
- JAVA连接MYSQL数据库以及操作
- Qt数据库操作 连接SQLite和MySQL数据库实例
- Qt数据库操作 连接SQLite和MySQL数据库实例
- Qt mysql 连接操作
- qt连接mysql数据库
- Qt 连接MySQL数据库
- Qt连接MySql数据库
- Qt 连接MYSQL数据库
- Qt连接MySQL数据库
- QT---连接mysql数据库
- Qt 连接MySQL数据库
- QT连接MYSQL数据库
- Qt连接MySQL数据库
- QT连接数据库的基本操作
- QT连接数据库的基本操作
- 程序员面试金典——寻找下一个结点
- 安全
- [IOS APP] 夜听刘筱
- 河南省第六届ACM程序设计大赛(共7道,目前只做了三道。待续)
- shell 编程——for in 循环
- qt连接mysql数据库以及txt文本的复制操作
- java <<(左移位) 与 >>(右移位)
- CF
- bootstrap-datetimepicker的引入
- STL初步 lower_bound & upper_bound UVa 10474
- C++对象数组和成员对象
- CenOS7安装Opentext Process Platform实践之平台篇
- 【 js 模块加载 】深入学习模块化加载(node.js 模块源码)
- JAR文件使用