[問題] 無法使用qt連接mysql早就創好的資料庫

看板C_and_CPP作者 (魯國王)時間8年前發表 (2017/04/06 11:14), 8年前編輯推噓4(402)
留言6則, 6人參與, 最新討論串1/1
開發平台(Platform): (Ex: Win10, Linux, ...) Linux Ubuntu14.04 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) Qt5.7.0 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 已先在終端機登入mysql並創建好資料庫和表格,但Qt無法連接讀取資料 餵入的資料(Input): 預期的正確結果(Expected Output): Database connection established 資料庫的資料 Closing... 錯誤結果(Wrong Output): Database connection established error: "no such table: country Unable to execute statement" Closing... 程式碼(Code):(請善用置底文網頁, 記得排版) QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE"); db.setHostName("localhost"); db.setUserName("root"); db.setPassword("4171"); db.setDatabaseName("world"); if(!db.open()) { qDebug()<<"Unable to open database"; return a.exec(); } else { qDebug()<<"Database connection established"; QSqlQuery qry; if(qry.exec("select * from country")) { while(qry.next()) { qDebug()<<qry.value(0).toString().trimmed(); } } else { qDebug()<<"error:"<<qry.lastError().text(); } qDebug()<<"Closing..."; db.close(); return a.exec(); } 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.117.167.198 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1491477265.A.CD3.html ※ 編輯: zxc123270 (140.117.167.198), 04/06/2017 19:15:09 ※ 編輯: zxc123270 (140.117.167.198), 04/06/2017 19:16:09

04/06 20:26, , 1F
你開mysql然後連sqlite?
04/06 20:26, 1F

04/06 21:09, , 2F
為什麼是sqlite?
04/06 21:09, 2F
我是智障嗎 = = 感謝各位解答,我明天去實驗室再改看看 ※ 編輯: zxc123270 (140.117.196.119), 04/06/2017 22:15:56

04/06 22:46, , 3F
XDDDDDDD
04/06 22:46, 3F

04/07 13:13, , 4F
...
04/07 13:13, 4F

04/07 14:55, , 5F
........
04/07 14:55, 5F

04/08 01:20, , 6F
……
04/08 01:20, 6F
文章代碼(AID): #1OvYCHpJ (C_and_CPP)