Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

Mysql with Qt query [solved]



  • Hello Forum,

    i have a question about MYSQL Syntax in Qt. I have a table with the name "min5_1" an i have problems with the query.

    The Code:

    @ MainWindow main;
    this->comboxLaden();
    QString tableName = ui->tablesBox->currentText();
    qDebug() << tableName;
    QSqlQueryModel *model = new QSqlQueryModel();
    QSqlQuery *qry = new QSqlQuery(main.mydb1);
    qry->prepare("SELECT * FROM '"+tableName+"' ");
    if(qry->exec())
    {
    qDebug() << "If schleife";
    model->setQuery(*qry);
    ui->anzeigenView->setModel(model);
    }
    else
    qDebug() << "Else" << qry->exec();@

    The exec is always false. When i changed the var "tableName" to "min5_1" the query is true. What doing false?

    Alex



  • Try to add:
    @
    qDebug() << "SELECT * FROM '"+tableName+"' ";
    qDebug() << "SELECT * FROM 'min5_1' ";
    @
    Hopefully, you will see the difference and reason for the misbehaviour.



  • try to debug the error, something like:

    @qDebug() << qry->lastError()->text();@



  • Thank you for the help. I have a syntax error
    @
    qry->prepare("select * from "+tableName+"");@


Log in to reply