Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Question in QSqlQuery



  • Hello Word
    Im New in Qt
    I have problem in m'y app
    This is m'y code

    voidDialog::on_tableView_activated(constQModelIndex&index)

    {

    QString valu=ui->tableView->model()->data(index).toString();QSqlQuery qryview;

    qryview.prepare("SELECT* FROM employ where nomper='"+valu+"' or prenomper='"+valu+"'")

    ui->lineEdit_2->setText(qryview.value(0).toString()); ui->lineEdit_3->setText(qryview.value(1).toString());}

    I want to recuperer m'y data in Qlineedit

    When i use sqlite no probleme
    But When i use mysql no resultat in linEdit


  • Lifetime Qt Champion

    Hi and welcome to the forums.
    Did you install mysql client libraries as well from their site?
    With Sqlite all is included but with MySql you have to supply the client libs your self. Maybe even build plugin.



  • @mrjj
    Yes i m install mysql client
    This is message debug
    qsqlquery::value: not positioned on a valid record


  • Lifetime Qt Champion

    @Binary said in Question in QSqlQuery:

    not positioned on a valid record

    Thats normally something with the syntax or no row was matched.
    Check what error() returns and try a plain "Select *" with no where part.
    also might just be a missing '



  • @mrjj
    this is queryDebug

    qsqlquery::value: not positioned on a valid record.


  • Lifetime Qt Champion

    @Binary
    Hi
    You grab the value directly
    qryview.value(1).toString());

    normally one will use first() or next() to place on valid record.
    please consult the docs. its explained in detail there.
    Normal sample is like

      QSqlQuery query("SELECT country FROM artist");
        while (query.next()) {
            QString country = query.value(0).toString();
          
        }
    


  • @mrjj said in Question in QSqlQuery:

    @Binary
    Hi
    You grab the value directly
    qryview.value(1).toString());

    normally one will use first() or next() to place on valid record.
    please consult the docs. its explained in detail there.
    Normal sample is like

      QSqlQuery query("SELECT country FROM artist");
        while (query.next()) {
            QString country = query.value(0).toString();
          
        }
    

    thank you


Log in to reply