Read tableWidget



  • 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



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

    Peter


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Are you sure you have an item in each cell ?



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



  • 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!



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.