Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Problem with QVariant, struct and SQLite

Problem with QVariant, struct and SQLite

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 2 Posters 1.3k 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.
  • J Offline
    J Offline
    joonne
    wrote on last edited by
    #1

    Hi,

    I have tried to search for an answer but didn't manage to get this work, and I don't know if this is even supposed to work. I am trying to insert my own struct as BLOB to SQLite database and the compile is ok but it is not working still.

    This is what I have tried:

    header:

    @struct serieinfo {
    int repeats_;
    double weights_;
    };

    Q_DECLARE_METATYPE(serieinfo)@

    source:

    @
    serieinfo temp1;
    temp1.repeats_ = 12;
    temp1.weights_ = 70;

    QVariant v;
    v.setValue(temp1);

    if (db.isOpen()) {

        QSqlQuery query;
    
        query.prepare(QString("INSERT INTO TEST VALUES(NULL,?,?,?,?,?,?,?)"));
    
        query.addBindValue("Bench Press");
        query.addBindValue(v);
        query.addBindValue(v);
        query.addBindValue(v);
        query.addBindValue(v);
        query.addBindValue(v);
        query.addBindValue(v);
    
        ret = query.exec();
    
        qDebug() << query.lastError();
    

    }@

    The SQLite table is created like this and it's working fine:

    @
    QSqlQuery query;
    ret = query.exec(QString("create table '%1'"
    "(id integer primary key, "
    "excercisename varchar(50), "
    "serie1 blob, "
    "serie2 blob, "
    "serie3 blob, "
    "serie4 blob, "
    "serie5 blob, "
    "serie6 blob)").arg(workoutname));
    @

    The outcome is that I have the table created but there is only "Bench Press". I am developing with Qt Creator on Windows 8. What am I doing wrong here? Thanks in advance!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tomasl
      wrote on last edited by
      #2

      Hi,

      I think your problem is that you try to bind a single value to multiple places in your query, which is not allowed.

      http://qt-project.org/doc/qt-5/qsqlquery.html#bindValue

      Tomas

      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