Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Can't connect to SQLite DB

Can't connect to SQLite DB

Scheduled Pinned Locked Moved Installation and Deployment
3 Posts 2 Posters 1.8k 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.
  • V Offline
    V Offline
    vaettchen
    wrote on last edited by
    #1

    Doing my first steps in Qt Creator and lost already:

    To a basic, otherwise unchanged starting app from the Qt wizzard, I have added sql to the project file

    @ QT += core gui sql@

    and the lines below to mainwindow.cpp.
    @
    #include <QSqlDatabase>

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("/home/vaettchen/testSQL/myDB.sqlite");
    bool db_ok = db.open();@
    

    According to various sources here on the Qt WebSite and on StackOverflow (where nobody could help me), I had expected that this would do it. But I get a compiler error

    @../testSQL/mainwindow.cpp:20:1: error: 'db' does not name a type@
    

    where line 20 is the db.setDataBaseName() line.
    I have tried to find out via Google what this means and what can be done about it but the comments I found were not very useful.

    Using Qt Creator 2.7.0 (Qt 4.8.4) on Linux 3.5

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SergioDanielG
      wrote on last edited by
      #2

      Hi vaettchen.
      Is libsqt4-sql and libqt4-sql-sqlite installed in your system?

      Regards.

      www.ftatv.com.ar El foro argentino de la TV libre

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vaettchen
        wrote on last edited by
        #3

        Thanks SergioDanielG - I do have the modules, drivers etc installed. This is all very confusing and, for a greenhorn like me, does look very inconcsistent.

        The odd thing is that depending how I start the project (from a sample project or plain wizzard) things seem to be different. I have partly solved the issue by prepending the command with void and other strange stuff that looks irregular to me.

        I have adapted the relationaltablemodel to use my existing sqlite file and make progress from here. I'll happily ask more questions once I understand better what I'm going at all...

        Thanks once more,
        Rainer

        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