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. How to access to dbf file in QT 5.14 ?
QtWS25 Last Chance

How to access to dbf file in QT 5.14 ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 399 Views
  • 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.
  • K Offline
    K Offline
    KellyWang
    wrote on last edited by mrjj
    #1

    Hi,

    System: Windows 10
    QT 5.14, Qt Creator

    My code:

    //code start ========================================
    QString dbFilePath = "D:\\data; //this is a directory 
    //QString dbFilePath = "D:\\data\\tmp.dbf;  //this is a dbf file,all tested
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    QString connString = QString("Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;DBQ=%1").arg(dbFilePath);
    db.setDatabaseName(connString);
    bool ret = db.open();
    
    QSqlQueryModel* p = new QSqlQueryModel;
    p->setQuery(QString("select col1,col2 from tmp"),db);
    //code end ===========================
    

    running failed : QSqlQuery::exec: database not open

    So how to access to dbf file in QT 5.14 ?

    Regards
    (mrJJ added code tags)

    jsulmJ 1 Reply Last reply
    0
    • K KellyWang

      Hi,

      System: Windows 10
      QT 5.14, Qt Creator

      My code:

      //code start ========================================
      QString dbFilePath = "D:\\data; //this is a directory 
      //QString dbFilePath = "D:\\data\\tmp.dbf;  //this is a dbf file,all tested
      QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
      QString connString = QString("Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;DBQ=%1").arg(dbFilePath);
      db.setDatabaseName(connString);
      bool ret = db.open();
      
      QSqlQueryModel* p = new QSqlQueryModel;
      p->setQuery(QString("select col1,col2 from tmp"),db);
      //code end ===========================
      

      running failed : QSqlQuery::exec: database not open

      So how to access to dbf file in QT 5.14 ?

      Regards
      (mrJJ added code tags)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @KellyWang First, add error handling to your code:
      https://doc.qt.io/qt-5/qsqldatabase.html#lastError.

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

      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Beside the good point of @jsulm :

        @KellyWang said in How to access to dbf file in QT 5.14 ?:

        QString dbFilePath = "D:\data\tmp.dbf; //this is a dbf file,all

        This is not a valid path, one backslash starts an escape sequence. If you want native Windows path you need to double all the backslashes or use the standard Unix notation and use QDir::toNativeSeparators.

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

        mrjjM 1 Reply Last reply
        3
        • SGaistS SGaist

          Hi and welcome to devnet,

          Beside the good point of @jsulm :

          @KellyWang said in How to access to dbf file in QT 5.14 ?:

          QString dbFilePath = "D:\data\tmp.dbf; //this is a dbf file,all

          This is not a valid path, one backslash starts an escape sequence. If you want native Windows path you need to double all the backslashes or use the standard Unix notation and use QDir::toNativeSeparators.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi
          @SGaist the poster has dual slashes but not using code tags so it's (was) not visible. (fixed)

          @KellyWang
          Did you install the actual dbf drivers ?
          They used to be part of
          https://www.microsoft.com/en-us/download/details.aspx?id=13255
          "Microsoft Access Database Engine 2010 Redistributable"
          but I have no clue if the driver still is :)

          1 Reply Last reply
          2

          • Login

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