create Excel file QSqlDatabase open error
-
I have a application QT, which create a Excel document. It works in my PC (Window7), and it works in another PC with windows 10. But it doesn't work in anohter Windows 7. I think it's a "dll forget" problem.
I have put qsqlite.dll, qsqlmysql.dll, qsqlodbc.dll, qsqlpsql.dll in my plugins file. Do a forget some DLL? -
Hi,
Did you also provide all related dependencies ?
-
Yes, i think so, the application can be used in all the Windows 7 and Windows 10 computer. But only in Windows 7, when i want to use the function "save the table in excel", i have a message to show QSqlDatabase open error.
here is my code which have le error.QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "excelexport"); if(!db.open()) { qDebug() << "ExportExcelObject::export2Excel failed: Create Excel file failed by DRIVER={Microsoft Excel Driver (*.xls)}."; //QSqlDatabase::removeDatabase("excelexport"); return -3; }
In this part, when i try my application in anther windows 7 computer, I have -3 as the return value. this is why i have an error message.
So do you have any idea, why it can't be open. -
@cdcc0606 You should print out the output of http://doc.qt.io/qt-5/qsqldatabase.html#lastError , it can help to find out what the problem is.
-
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "excelexport"); if(!db.isValid()) { qDebug() << "ExportExcelObject::export2Excel failed: QODBC not supported."; return -2; } /* set the dsn string*/ QString dsn = QString("DRIVER={Microsoft Excel Driver (*.xls)};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%1\";DBQ=%2"). arg(excelFilePath).arg(excelFilePath); db.setDatabaseName(dsn); if(!db.open()) { qDebug() << "ExportExcelObject::export2Excel failed: Create Excel file failed by DRIVER={Microsoft Excel Driver (*.xls)}."; //QSqlDatabase::removeDatabase("excelexport"); return -3; }
see here is my code for this part.