[Solved] How to use SQL model with Qt5 layer?

Discussion in 'Yocto' started by cyrilf, Nov 4, 2016.

Tags:
  1. cyrilf

    cyrilf Active Member

    Joined:
    Feb 19, 2015
    Messages:
    168
    Likes Received:
    47
    Hi,

    I wonder how to enable classes such as QSqlTableModel with the Qt5 layer? I have a SQlite database so maybe I also have to enable the SQlite driver?

    Here is my code:
    Code:
    #ifndef MACHINE
    #define MACHINE
    
    #include <QSqlTableModel>
    
    class Machine : public QSqlTableModel
    {
    
    };
    
    #endif // MACHINE
    At the include line, I get an error "No such file or directory".

    Thanks in advance.

    Edit: I simply forgot to add
    Code:
    QT += sql
    to my .pro file.
     
    Last edited: Nov 4, 2016
    graugans and modjo like this.
  2. modjo

    modjo Active Member

    Joined:
    Sep 29, 2014
    Messages:
    417
    Likes Received:
    127
    Yes, don't forget to add the module in .pro file when you want to use it (widget, network ...)
     
    graugans likes this.
  3. cyrilf

    cyrilf Active Member

    Joined:
    Feb 19, 2015
    Messages:
    168
    Likes Received:
    47
    Now I have a trouble with the SQlite Driver (QSQLITE driver not loaded). I try to figure out how to add this driver.
     
  4. graugans

    graugans Administrator Staff Member

    Joined:
    Sep 17, 2015
    Messages:
    328
    Likes Received:
    141
  5. cyrilf

    cyrilf Active Member

    Joined:
    Feb 19, 2015
    Messages:
    168
    Likes Received:
    47
    Yes, I solved it by the time just by adding a .bbappend file.

    meta-udoo/recipes-qt/qt5/qtbase_%.bbappend:
    Code:
    PACKAGECONFIG_append = " sql-sqlite"
    I would prefer not to create a new file for only one line but it works actually.
     
    modjo and graugans like this.
  6. graugans

    graugans Administrator Staff Member

    Joined:
    Sep 17, 2015
    Messages:
    328
    Likes Received:
    141
    You can change this for example in the conf/local.conf file.
    Code:
    PACKAGECONFIG_append_pn-qtbase= " sql-sqlite"
    So no .bbappend is needed Or if you haveyour own distro you can set it in the distro file.
     
    modjo and cyrilf like this.

Share This Page