Rev 92 | Rev 94 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 92 | Rev 93 | ||
---|---|---|---|
Line 11... | Line 11... | ||
11 | 11 | ||
12 | //QString model_str;
|
12 | //QString model_str;
|
13 | MainWindow::creatModelString(); |
13 | MainWindow::creatModelString(); |
14 | int i; |
14 | int i; |
15 | i++; |
15 | i++; |
16 | QFile file_tmp("temp.txt"); |
16 | QFile file_tmp("./temp.txt"); |
17 | bool ok; |
17 | bool ok; |
18 | ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text); |
18 | ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text); |
19 | QTextStream out(&file_tmp); |
19 | QTextStream out(&file_tmp); |
20 | out << MainWindow::modelString; |
20 | out << MainWindow::modelString; |
21 | file_tmp.close(); |
21 | file_tmp.close(); |
22 | 22 | ||
- | 23 | MainWindow::openDataBase(); |
|
- | 24 | ||
23 | }
|
25 | }
|
24 | 26 | ||
25 | MainWindow::~MainWindow() |
27 | MainWindow::~MainWindow() |
26 | {
|
28 | {
|
27 | delete ui; |
29 | delete ui; |
Line 227... | Line 229... | ||
227 | 229 | ||
228 | }
|
230 | }
|
229 | int i; |
231 | int i; |
230 | i++; |
232 | i++; |
231 | }
|
233 | }
|
- | 234 | ||
- | 235 | ||
- | 236 | bool MainWindow::openDataBase(){ |
|
- | 237 | QString errorString;
|
|
- | 238 | sql = QSqlDatabase::addDatabase("QMYSQL"); |
|
- | 239 | sql.setDatabaseName(tr("an_db")); |
|
- | 240 | sql.setHostName(tr("localhost")); |
|
- | 241 | sql.setUserName(tr("an")); |
|
- | 242 | sql.setPassword(tr("393939")); |
|
- | 243 | ||
- | 244 | bool ok; |
|
- | 245 | ok = sql.open(); |
|
- | 246 | ||
- | 247 | /*
|
|
- | 248 | if (!ok) {
|
|
- | 249 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
|
- | 250 | this, // Ðîäèòåëüñêèé âèäæåò.
|
|
- | 251 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
|
- | 252 | sql.lastError().text() ); // Òåêñò ñîîáùåíèÿ.
|
|
- | 253 | ||
- | 254 | ||
- | 255 | }
|
|
- | 256 | ||
- | 257 | */
|
|
- | 258 | if (!ok) { |
|
- | 259 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
|
- | 260 | this, // Ðîäèòåëüñêèé âèäæåò. |
|
- | 261 | QObject::tr("Database Error"), // Çàãîëîâîê. |
|
- | 262 | sql.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
|
- | 263 | }
|
|
- | 264 | else { |
|
- | 265 | ||
- | 266 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
|
- | 267 | this, // Ðîäèòåëüñêèé âèäæåò. |
|
- | 268 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
|
- | 269 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
|
- | 270 | ||
- | 271 | ||
- | 272 | ||
- | 273 | ||
- | 274 | ||
- | 275 | }
|
|
- | 276 | ||
- | 277 | return ok; |
|
- | 278 | }
|