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. Why is it invalid using value() of QSqlRecord?

Why is it invalid using value() of QSqlRecord?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.1k Views 3 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.
  • C Offline
    C Offline
    CoderJeff
    wrote on last edited by koahnig
    #1
        QSqlTableModel *tblModel = (QSqlTableModel*)ui->tableView->model();
        tblModel->setTable("TableTest");
        QSqlRecord rec = tblModel->record(ui->tableView->currentIndex().row());
        QVariant var;
        if(!rec.isEmpty())
        {
            var = rec.value(0);
        }
    

    Although rec is not empty, var is always invalid.

    Why?

    K 1 Reply Last reply
    0
    • C CoderJeff
          QSqlTableModel *tblModel = (QSqlTableModel*)ui->tableView->model();
          tblModel->setTable("TableTest");
          QSqlRecord rec = tblModel->record(ui->tableView->currentIndex().row());
          QVariant var;
          if(!rec.isEmpty())
          {
              var = rec.value(0);
          }
      

      Although rec is not empty, var is always invalid.

      Why?

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @CoderJeff

      How do you use var?
      You might have to use one of those methods e.g. toDouble().

      Vote the answer(s) that helped you to solve your issue(s)

      C 1 Reply Last reply
      0
      • K koahnig

        @CoderJeff

        How do you use var?
        You might have to use one of those methods e.g. toDouble().

        C Offline
        C Offline
        CoderJeff
        wrote on last edited by CoderJeff
        #3

        @koahnig

        Before using toDouble or other methods, var should be valid. But it is always invalid in fact.

        I tried using toInt and toString, and the result was always 0.

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @CoderJeff said:

          QSqlRecord rec = tblModel->record(ui->tableView->currentIndex().row());

          What is the value of ui->tableView->currentIndex().row()?

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          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