vendredi 25 septembre 2015

Qt & sqlite: Can't save the query.value in a variable

I'm using QT and I want to use a sqlite database to draw an ellipse with x and y coordinates and width and height sizes.

I've successfully implementet the database (the .db file is in my working folder, in this case the release folder) and now I want to save the values you insert into the database in a variable.

      QSqlQuery query;
      QString queryString = QString::fromUtf8("select * from tableEllipse;");
      if(!query.exec(queryString))
      {
        qDebug() << "Error"
      }

      while (query.next())
      {
          int id = query.value(0).toInt;
          int x = query.value(1).toInt;
          int y = query.value(2).toInt;
          int width = query.value(3).toInt;
          int height = query.value(4).toInt;

          qDebug() << x << y << width << height;
      }

I filled my table once with some values. If I try to run my program, I get this following error:

cannot convert 'QVariant::toInt' from type 'int (QVariant::)(bool*) const' to type 'int'

But in my database all the values are integers!

CREATE TABLE tableEllipse
(
ellipseID integer primary key,
ellipseX integer,
ellipseY integer,
ellipseWidth integer,
ellipseHeight integer
);

Aucun commentaire:

Enregistrer un commentaire