Home > Software design >  How do you save a setquery count to a string in Qt
How do you save a setquery count to a string in Qt

Time:11-15

 QSqlQueryModel * model=new QSqlQueryModel ();
    int i,id;
    QString count;
    model->setQuery("SET '" count "' =(SELECT COUNT(*) from COLLABORATEUR)");

   qInfo() << count;

i tried this code but count is still clear i always get "" i tried it like this too:

model->setQuery("SELECT '" count "'=COUNT(*) from COLLABORATEUR");

and like this :

model->setQuery("SELECT @count=COUNT(*) from COLLABORATEUR");

but count is still empty

CodePudding user response:

If you just need to count the number of records, then use directly rowCount().

QString count = QString::number(model->rowCount());
qInfo() << count;
  • Related