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. Read tableWidget
Qt 6.11 is out! See what's new in the release blog

Read tableWidget

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

    Hello. My Qt version is 4.8

    I want enter by keyboard data to tableWidget and then read it.
    How i can do it ?

    I try to do the following.

    @
    iColumns=ui.tableWidget->columnCount();
    iRows=ui.tableWidget->rowCount();
    for(int i=0;i<iRows;++i)
    {
    for(int j=0;j<iColumns;++j)
    {
    //QTableWidgetItem *item=ui.tableWidget->item(i,j);
    //QString temp=item->text();
    //std::cout<<temp.toAscii().data()<<std::endl;

     QMessageBox msgBox;
     QTableWidgetItem* theItem = ui.tableWidget->item(i,j);
     QString theText = theItem->text();
     msgBox.about(this,"Test",theText);
    }
    

    }
    @

    it's not work.

    if i use the commented code lines show me "Qt has caught an exception thrown from an event handler. Throwing exceptions from an event handler is not supported in Qt. You must reimplement QApplication::notify() and catch all exceptions there"

    How to solve my problem ?

    thanks

    1 Reply Last reply
    0
    • D Offline
      D Offline
      donjuedo
      wrote on last edited by
      #2

      Have you tried single-step debugging to see which line is offending?

      Peter

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

        Hi and welcome to devnet,

        Are you sure you have an item in each cell ?

        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
        • K Offline
          K Offline
          kamgo
          wrote on last edited by
          #4

          I entered in each cell some digit value by hands for testing. It's the same error/exception

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            Hi,
            When a QTableWidget is created all the cells are "empty". You need to add a widget to every cell to hold text/icons etc. The QTableWidget will be the parent of the items, so no cleanup is needed after it.
            In your code this line
            @
            QTableWidgetItem* theItem = ui.tableWidget->item(i,j);
            @
            will probably return '0' pointer. So the next line to read the text will crash your program!
            After generation of the table, add the items:
            @
            ui->tableWidget.setItem(i,j) = new QTableWidgetItem;
            @
            Hope this helps!

            Greetz, Jeroen

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kamgo
              wrote on last edited by
              #6

              i create my table by Qt designer. So what do you mean by "After generation of the table" ?

              Sorry i just started to learn Qt

              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