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. Item in QTableWidget

Item in QTableWidget

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.7k 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.
  • V Offline
    V Offline
    Vidhya
    wrote on last edited by
    #1

    how can i check the item in the Qtablewidget having value or not

    Regards,
    Vidhya

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      What exactly do you mean by this?
      AFAIK there is a method to get a pointer to an item, then you can query the values of the item. Does that help you?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vidhya
        wrote on last edited by
        #3

        @for (int row=0 ; row < ui->widget->rowCount();row++)
        {
        qDebug()<<"Ckeck point X "<<row;
        QTableWidgetItem *item_test = ui->widget->item(row, 0);
        if(!item_test->text().isEmpty())
        {
        check_count++;
        qDebug()<<"Checkpoint y "<<row;
        }
        c++;
        }
        qDebug()<<"Check Count"<<check_count;@

        for first loop(row=0) its working but in the next loop(row=1) it displays Ckeck point X 1;then the program is terminated

        pls help me to fix this problem

        Regards,
        Vidhya

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Always check if a pointer you get back from a method call that returns one is valid before dereferencing it. You are using item_test without checking if it is valid in line 5.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Vidhya
            wrote on last edited by
            #5

            sorry i didn't catch your point.
            Can u pls explain in detail.

            Regards,
            Vidhya

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Take a look at these lines:
              @
              QTableWidgetItem *item_test = ui->widget->item(row, 0);
              if(!item_test->text().isEmpty())
              @

              What happens if line 1 above sets item_test to 0? In line 2 you dereference the pointer, but you have no idea if the pointer is valid or not. So, do this instead:

              @
              QTableWidgetItem *item_test = ui->widget->item(row, 0);
              if(item_test) {
              if(!item_test->text().isEmpty()) {
              @

              Though you could combine that to:
              @
              QTableWidgetItem *item_test = ui->widget->item(row, 0);
              if(item_test && !item_test->text().isEmpty())
              @

              Dereferencing a 0 (or an otherwise invalid) pointer will lead you into "undefined behaviour", usually leading to a crash or worse. Using either *the_pointer. or the_pointer-> is called dereferencing the pointer. That is: not trying to use the pointer as such, but the thing it points to. If the thing it points to is invalid, that will go wrong.

              1 Reply Last reply
              0
              • V Offline
                V Offline
                Vidhya
                wrote on last edited by
                #7

                Thank U ,

                Regards,
                Vidhya

                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