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. QSqlDatabase setDatabaseName qrc
Forum Updated to NodeBB v4.3 + New Features

QSqlDatabase setDatabaseName qrc

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 403 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.
  • Y Offline
    Y Offline
    yunjungao
    wrote on last edited by yunjungao
    #1

    this is my code:
    QSqlDatabase sqliteDatabase =QSqlDatabase::addDatabase("QSQLITE");;
    QString dateBaseFile(":/file/global.db");
    QFile file(dateBaseFile);
    if (!file.exists())
    {
    return;
    }

    sqliteDatabase.setDatabaseName(dateBaseFile);
    bool bOpenFlag = sqliteDatabase.open();
    

    if (!bOpenFlag)
    {
    qDebug()<< sqliteDatabase.lastError();
    }
    dateBaseFile is copied from QRC, and the path has been checked to be correct, but the database cannot be opened. The Error information is QSqlError("-1", "Error opening database", "out of memory").Has anyone ever experienced this before?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You can't open a db from a resource - sqlite doesn't know anything about this. You have to copy it to a local file.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Y 1 Reply Last reply
      2
      • B Offline
        B Offline
        Bonnie
        wrote on last edited by
        #3

        I don't think sqlite can read a qrc file.

        1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          You can't open a db from a resource - sqlite doesn't know anything about this. You have to copy it to a local file.

          Y Offline
          Y Offline
          yunjungao
          wrote on last edited by
          #4

          @Christian-Ehrlicher
          Ok, thanks for your reply

          1 Reply Last reply
          0

          • Login

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