main.cpp
- #include "mainwindow.h"
- #include <QApplication>
- #include <QSqlDatabase>
- #include <QSqlQuery>
- #include <cstdlib> /* 亂數相關函數 */
- #include <string>
- using namespace std;
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- MainWindow w;
- w.show();
- w.connectDB();
- QSqlQuery query;
- query.exec("drop database if exists course6");
- query.exec("create database course6");
- query.exec("use course6");
- query.exec("drop table if exists peoplelist");
- query.exec("create table peoplelist(id char(8),nowfloor int,destination int,number int)");
- query.exec("load data infile \'C:/test/data.csv\' into table peoplelist fields terminated by \',\' enclosed by \'\"\' lines terminated by \'\\n\' ignore 1 rows");
- w.ini = rand()%30;
- w.t = QString::number(w.ini);
- query.prepare("select * from peoplelist where id like concat('%',?,'-%')");
- query.addBindValue(w.t);
- query.exec();
- query.next();
- for(int i=0;i<10;i++){
- w.id[i] = query.value(0).toString().toStdString();
- w.now[i] = query.value(1).toInt();
- w.des[i] = query.value(2).toInt();
- w.num[i] = query.value(3).toInt();
- query.next();
- }
- return a.exec();
- }
複製代碼 |