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. QTableWidget problem
Forum Updated to NodeBB v4.3 + New Features

QTableWidget problem

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

    Hi, I have a problem and I don't know why.

    So, I have a QTable widget, (10 rows, 8 columns) in my case. With a loop I create in three column a QTableWidgetItem.
    I use table->setItem(currentRow,2,new QTableWidgetItem); and the same for column 3 and 4.
    I am sure that these lines are called and currentRow index take all values from 0 to 9.

    The problem is, when I use cell, my software crash.
    I use table->item(i,2)->setBackgroundColor(Qt::darkGray); 0<=i<=9 it's sure, I print "i" index;
    The setBackgroundColor works but I use the line directly after setText(text) or text() and now the software crash.
    The QTableWiodgetItem exists, and it's works for one method and not for setText and text.

    Someone have an idea ?

    Sorry for my english. If you need more information, tell me.

    Thanks a lot.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Hi Paco,
      you should give some code sample. That would help to understand your problem.

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

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Paco
        wrote on last edited by
        #3

        when I initialize my table:
        @
        for(int currentRow=0; currentRow<nbRow; ++currentRow) {
        ...
        if(nbSystem>1) {
        table->setSpan(currentRow,2,nbSystem,1);
        table->setSpan(currentRow,3,nbSystem,1);
        table->setSpan(currentRow,4,nbSystem,1);
        }

        table->setItem(currentRow,2,new QTableWidgetItem);
        table->setItem(currentRow,3,new QTableWidgetItem);
        table->setItem(currentRow,4,new QTableWidgetItem);
        ...
        }
        @

        And when I use it:
        @
        for(int currentRow=0; currentRow<nbRow; ++currentRow) {
        QString posX = posList.at(6);
        QString posY = posList.at(7);
        QString posZ = posList.at(8);

        table->item(i,2)->setBackgroundColor(Qt::darkGray);
        table->item(i,2)->setText(posX);
        table->item(i,3)->setBackgroundColor(Qt::darkGray);
        table->item(i,3)->setText(posY);
        table->item(i,4)->setBackgroundColor(Qt::darkGray);
        table->item(i,4)->setText(posZ);
        

        }
        @

        When the setText() is called, my software crash

        Sorry I can't copying my real code because it is on an another computer and I can't put USB key.

        I think perhaps the problem is the setSpan but it's not sure

        [edit: code highlighted / Denis Kormalev]

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Paco
          wrote on last edited by
          #4

          Sory now the setBackgoundColor doesn't work, I don't know why, but the object is created and the address in the cell is not NULL.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DenisKormalev
            wrote on last edited by
            #5

            Please don't forget to highlight code with @ tags. I've done it in your last comment for you, but in future please do it yourself

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Paco
              wrote on last edited by
              #6

              Ho it's ok, I find it, sorry for all the desagreement. For the next time I will know that I need to use @ tag.

              My problem is I print the address before I modify it in an other function. And the new address it was NULL.

              Thank's for all

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

                You set row spans in your first method. Be sure to not access any of the cells that are spanned over in the second method.

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

                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