Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. create Excel file QSqlDatabase open error
Forum Updated to NodeBB v4.3 + New Features

create Excel file QSqlDatabase open error

Scheduled Pinned Locked Moved Solved General and Desktop
qsqlexcel
7 Posts 4 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cdcc0606
    wrote on 24 Oct 2017, 14:02 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 24 Oct 2017, 20:04 last edited by
      #2

      Hi,

      Did you also provide all related dependencies ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cdcc0606
        wrote on 25 Oct 2017, 06:15 last edited by
        #3

        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.

        J V 2 Replies Last reply 25 Oct 2017, 06:32
        0
        • C cdcc0606
          25 Oct 2017, 06:15

          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.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 25 Oct 2017, 06:32 last edited by
          #4

          @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.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • C cdcc0606
            25 Oct 2017, 06:15

            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.

            V Offline
            V Offline
            VRonin
            wrote on 25 Oct 2017, 07:34 last edited by
            #5

            Where do you set the database name?
            see https://wiki.qt.io/Handling_Microsoft_Excel_file_format

            Are you using windeployqt?

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cdcc0606
              wrote on 25 Oct 2017, 07:44 last edited by
              #6
              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.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                cdcc0606
                wrote on 25 Oct 2017, 08:19 last edited by
                #7

                It's Ok, i found the problem.
                I have to define the full path DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)} to avoid the error message

                1 Reply Last reply
                3

                2/7

                24 Oct 2017, 20:04

                topic:navigator.unread, 5
                • Login

                • Login or register to search.
                2 out of 7
                • First post
                  2/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved