Problems with Open-Source Downloads read and

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;
    QString tableName = ui->tablesBox->currentText();
    qDebug() << tableName;
    QSqlQueryModel *model = new QSqlQueryModel();
    QSqlQuery *qry = new QSqlQuery(main.mydb1);
    qry->prepare("SELECT * FROM '"+tableName+"' ");
    qDebug() << "If schleife";
    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?


  • 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