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. [SOLVED] QTableWidgetItem cant read text
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QTableWidgetItem cant read text

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 11.0k 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.
  • X Offline
    X Offline
    xeroblast
    wrote on last edited by
    #1

    i have this little problem that uses a lot of my time. this is about the qtablewidgetitem identifying if it is empty or not..

    @
    for (int row=0; row < rows; row++) {
    if (qtablewidget->item(row, col)->text().isEmpty()) {
    }
    }
    @

    the error : Symbol this is a variable with complex or multiple locations (DWARF2)

    the error will appear if you leave the cell empty.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      milot.shala
      wrote on last edited by
      #2

      [quote author="xeroblast" date="1293521365"]i have this little problem that uses a lot of my time. this is about the qtablewidgetitem identifying if it is empty or not..

      @
      for (int row=0; row < rows; row++) {
      if (qtablewidget->item(row, col)->text().isEmpty()) {
      }
      }
      @

      the error : Symbol this is a variable with complex or multiple locations (DWARF2)

      the error will appear if you leave the cell empty.[/quote]

      What about using QTableView? You can reach your goal in much nicer way.

      On the other hand can you also check if it returns 0, I don't use QTableWidget myself but according to the documentation, is the statement below:

      bq. QTableWidgetItem * QTableWidget::item ( int row, int column ) const
      Returns the item for the given row and column if one has been set; otherwise returns 0.

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xeroblast
        wrote on last edited by
        #3

        i cant use qtableview because the table is editable by double clicking..

        1 Reply Last reply
        0
        • M Offline
          M Offline
          milot.shala
          wrote on last edited by
          #4

          [quote author="xeroblast" date="1293527835"]i cant use qtableview because the table is editable by double clicking..[/quote]

          You can do that as well. But read more about "Model/View Programming":http://doc.qt.nokia.com/latest/model-view-programming.html and see that you can do more cool things besides basic editing.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            The error "Symbol this is a variable with complex or multiple locations " is from the debugger. It's most likely that you are thrown into the debugger because your application crashes because of a null pointer access. You must check if the item pointer is valid!

            Change your method:

            @
            for (int row=0; row < rows; ++row) {
            if(QTableWidgetItem *item = qtablewidget->item(row, col)) {
            if(item->text().isEmpty()) {
            }
              }
            }
            @

            http://www.catb.org/~esr/faqs/smart-questions.html

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

              Â bit more description to Volkers answer:

              In a QTableWidget you can define tghe numbers of rows and columns. By default, no cell has a QTableWidgetItem behind its data, so qtablewidget->item(row, col) will return a null pointer. Only if you fill the table with items, all filled tables will return a valid pointer. So it is a MUST to check the returned pointer.

              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
              • X Offline
                X Offline
                xeroblast
                wrote on last edited by
                #7

                thank you..
                i also solve it using it like this :

                @
                for (int row=0; row < rows; row++) {
                if (!qtablewidget->item(row, col)) {
                }
                }
                @

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  Then you have to call item(row, col) a second time to get to the actual value. This might be quite time consuming if you have a big table. Why not reuse the value that you peeked out just before?

                  [EDIT: add]

                  [quote author="xeroblast" date="1293587463"]thank you..
                  i also solve it using it like this :
                  @
                  for (int row=0; row < rows; row++) {
                  if (!qtablewidget->item(row, col)) {
                  }
                  }
                  @[/quote]

                  The if clause is true, if you have no item at the specified position!

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • X Offline
                    X Offline
                    xeroblast
                    wrote on last edited by
                    #9

                    you are right Volker but i only use it as a checker.. that is why i use the negation..

                    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