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. column out of range problem

column out of range problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 853 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    rahulvishwakarma
    wrote on last edited by
    #1

    i am building small project, in Qt 5.7(on client) and mysql( on server). then in following program I stuck in "QMYSQLResult::data: column 1 out of range" problem. please help how to get rid of this.

    void Sales::on_comboBoxName_currentTextChanged(const QString &arg1)
    {
        QString sql = "select productID, Rate, Stock from tableProductRecords where productname Like '%"+arg1+ "%';";
        query->prepare(sql);
        if(query->exec(sql))
        {
            if(query->next())
            {
                ui->lineEditProductNumber->setText(query->value(0).toString().trimmed());
                qDebug() << "ui->lineEditProductNumber->text().trimmed();" << ui->lineEditProductNumber->text().trimmed();
                QString str1 = query->value(1).toString().trimmed();
    
                ui->lineEditRate->setText(str1); // here is error of column out of range
                qDebug() <<" ui->lineEditRate->text().trimmed(); " << ui->lineEditRate->text().trimmed();
                QString str2 = query->value(2).toString().trimmed();
                ui->lineEditStock->setText(str2);// here is error of column out of range
                qDebug() <<"ui->lineEditStock->text().trimmed();" <<   ui->lineEditStock->text().trimmed();
            }
        }
    }
    

    output :-

    ui->lineEditProductNumber->text().trimmed(); "1"
    
    QMYSQLResult::data: column 1 out of range
    
     ui->lineEditRate->text().trimmed();  ""
    
    QMYSQLResult::data: column 2 out of range
     ui->lineEditStock->text().trimmed(); ""
    
    ui->lineEditProductNumber->text().trimmed(); "1"
    
     ui->lineEditRate->text().trimmed();  "7000"
     ui->lineEditStock->text().trimmed(); "4"
    

    how do I get rid of "column out of range".

    JonBJ 1 Reply Last reply
    0
    • R rahulvishwakarma

      i am building small project, in Qt 5.7(on client) and mysql( on server). then in following program I stuck in "QMYSQLResult::data: column 1 out of range" problem. please help how to get rid of this.

      void Sales::on_comboBoxName_currentTextChanged(const QString &arg1)
      {
          QString sql = "select productID, Rate, Stock from tableProductRecords where productname Like '%"+arg1+ "%';";
          query->prepare(sql);
          if(query->exec(sql))
          {
              if(query->next())
              {
                  ui->lineEditProductNumber->setText(query->value(0).toString().trimmed());
                  qDebug() << "ui->lineEditProductNumber->text().trimmed();" << ui->lineEditProductNumber->text().trimmed();
                  QString str1 = query->value(1).toString().trimmed();
      
                  ui->lineEditRate->setText(str1); // here is error of column out of range
                  qDebug() <<" ui->lineEditRate->text().trimmed(); " << ui->lineEditRate->text().trimmed();
                  QString str2 = query->value(2).toString().trimmed();
                  ui->lineEditStock->setText(str2);// here is error of column out of range
                  qDebug() <<"ui->lineEditStock->text().trimmed();" <<   ui->lineEditStock->text().trimmed();
              }
          }
      }
      

      output :-

      ui->lineEditProductNumber->text().trimmed(); "1"
      
      QMYSQLResult::data: column 1 out of range
      
       ui->lineEditRate->text().trimmed();  ""
      
      QMYSQLResult::data: column 2 out of range
       ui->lineEditStock->text().trimmed(); ""
      
      ui->lineEditProductNumber->text().trimmed(); "1"
      
       ui->lineEditRate->text().trimmed();  "7000"
       ui->lineEditStock->text().trimmed(); "4"
      

      how do I get rid of "column out of range".

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @rahulvishwakarma said in column out of range problem:

      QMYSQLResult::data: column 1 out of range

      You asked this question at https://www.qtcentre.org/threads/71156-column-out-of-range-problem a week ago. I'm afraid the answer is the same as there, you really need to do error checking and you are not:

      QSqlQuery::isNull(), QSqlQuery::isValid(), QVariant::isValid(), QVariant::isNull(), QVariant::canConvert() are just a few of the methods available that might result in more reliable code and fewer error messages.

      At a guess, the Rate and Stock returned from your row have value NULL? Have you looked at what you have actually put in the row in your database?

      1 Reply Last reply
      3
      • R Offline
        R Offline
        rahulvishwakarma
        wrote on last edited by
        #3

        I tried as you said and getting nothing as follows:-

        bool flag = query->isActive();
        QMessageBox::information(this, "on_comboBoxName_currentTextChanged", " str1 : "  + flag);
        

        it prints nothing

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          You have two if statements that checks both if the execution was successful as well as the next call. Put an else close for each of them and there print the error you may have.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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