Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. invalid operands to binary expression ('const char *' and 'QString')
Forum Updated to NodeBB v4.3 + New Features

invalid operands to binary expression ('const char *' and 'QString')

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 5.0k 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.
  • T Offline
    T Offline
    TheCipo76
    wrote on 21 Sept 2018, 11:52 last edited by
    #1

    Hi, i'va a problem to compare different type of text..

    if (!aDatabase.open())
            {
            // Messaggio Errore
            QMessageBox::critical(this, "Errore", aDatabase.lastError().text());
            return;
            }
        //COMBO CODICE - DA DATABASE
        QSqlQuery q;
        q.prepare("Select CODICE from ARTICOLI where Cliente == " & ui->comboBox_Cliente->currentText() &  " order by CODICE");
        if (ui->comboBox_Cliente->currentText() == "")
            {
            QMessageBox::warning(this, "Errore", "Selezionare prima il Cliente!");
            return;
            }
        if (q.exec())
            {
                QSqlQueryModel *TModel = new QSqlQueryModel(this);
                TModel->setQuery(q);
                ui->comboBox_Codice->setModel(TModel);
            }
    

    compiling i've this error but idon't know how solve it..

    .../regtemciclo.cpp:81: error: invalid operands to binary expression ('const char *' and 'QString')
    q.prepare("Select CODICE from ARTICOLI where Cliente == " & ui->comboBox_Cliente->currentText() & " order by CODICE");
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    anyone help me please??

    J 1 Reply Last reply 21 Sept 2018, 11:57
    0
    • T TheCipo76
      21 Sept 2018, 11:52

      Hi, i'va a problem to compare different type of text..

      if (!aDatabase.open())
              {
              // Messaggio Errore
              QMessageBox::critical(this, "Errore", aDatabase.lastError().text());
              return;
              }
          //COMBO CODICE - DA DATABASE
          QSqlQuery q;
          q.prepare("Select CODICE from ARTICOLI where Cliente == " & ui->comboBox_Cliente->currentText() &  " order by CODICE");
          if (ui->comboBox_Cliente->currentText() == "")
              {
              QMessageBox::warning(this, "Errore", "Selezionare prima il Cliente!");
              return;
              }
          if (q.exec())
              {
                  QSqlQueryModel *TModel = new QSqlQueryModel(this);
                  TModel->setQuery(q);
                  ui->comboBox_Codice->setModel(TModel);
              }
      

      compiling i've this error but idon't know how solve it..

      .../regtemciclo.cpp:81: error: invalid operands to binary expression ('const char *' and 'QString')
      q.prepare("Select CODICE from ARTICOLI where Cliente == " & ui->comboBox_Cliente->currentText() & " order by CODICE");
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      anyone help me please??

      J Online
      J Online
      JonB
      wrote on 21 Sept 2018, 11:57 last edited by JonB
      #2

      @TheCipo76

      q.prepare("Select CODICE from ARTICOLI where Cliente == " & ui->comboBox_Cliente->currentText() &  " order by CODICE");
      

      Let's start with: What in the world is that & operator supposed to be? If it's string concatenation, that's + in C++, we're not in Visual Basic here! :)

      Then you might want to look at http://doc.qt.io/qt-5/qstring.html#arg as a neater way of accomplishing it.:

      QString("Select CODICE from ARTICOLI where Cliente == %1 order by CODICE").arg(ui->comboBox_Cliente->currentText())
      

      Up to you, matter of preference.

      Finally, you sure == is the right operator to pass in your query? Last time I looked SQL's operator is =, but you may know better for your SQL provider.

      1 Reply Last reply
      3
      • T Offline
        T Offline
        TheCipo76
        wrote on 21 Sept 2018, 12:03 last edited by
        #3

        ooops.. you're right!!
        Thank you

        J 1 Reply Last reply 21 Sept 2018, 12:04
        0
        • T TheCipo76
          21 Sept 2018, 12:03

          ooops.. you're right!!
          Thank you

          J Online
          J Online
          JonB
          wrote on 21 Sept 2018, 12:04 last edited by JonB
          #4

          @TheCipo76
          Check what I've added about your SQL == operator?

          Also, if your ui->comboBox_Cliente->currentText() is some literal text (as opposed to a SQL expression), won't you need SQL quote marks around it, like say:

          QString("Select CODICE from ARTICOLI where Cliente == '%1' order by CODICE").arg(ui->comboBox_Cliente->currentText())
          

          And even then it won't work right if the literal string contains a ' character....

          1 Reply Last reply
          0

          1/4

          21 Sept 2018, 11:52

          • Login

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