Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. Mysql with Qt query [solved]
QtWS25 Last Chance

Mysql with Qt query [solved]

Scheduled Pinned Locked Moved German
4 Posts 3 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nickvan86
    wrote on last edited by
    #1

    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

    Qt 5.2.1 Creator 3.0.1 Windows 7 64bit

    1 Reply Last reply
    0
    • C Offline
      C Offline
      clochydd
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Code_ReaQtor
        wrote on last edited by
        #3

        try to debug the error, something like:

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

        Please visit my open-source projects at https://github.com/Code-ReaQtor.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nickvan86
          wrote on last edited by
          #4

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

          Qt 5.2.1 Creator 3.0.1 Windows 7 64bit

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved