[email protected]
[Top] [All Lists]

Re: QTableWidget-Problem (any comments?)

Subject: Re: QTableWidget-Problem any comments?
From: Kavindra Palaraja
Date: Wed, 28 Nov 2007 13:09:14 +0100
Ionathan wrote:

I am porting an application from qt3 to qt4 /under Suse Linux 10.2/. The
tool qt3to4 did not work correctly.

Thus I am trying to redo the whole under qt4. One class I need shall bei
based on the qt/example "findfiles" ...

Here I want to use the QTableWidget together with QTableWidgetItem. I
can see the items and I also generated a signal when doublecliqueing
within a cell of QTableWidget.

However when I tried to extract the text of row x and column 0 of that
QTableWidgetItem the system crashes or it does not correctly compile. I
use a QDatastream object but this seems not to be the correct way.

A code snippet is put down here.
I would appreciate a constructive hint or answer ... thanks Joerg

// this code snippet is from Trolltech:

 QComboBox *Window::createComboBox(const QString &text)
     QComboBox *comboBox = new QComboBox;
     return comboBox;

// this code is also from Trolltech plus a connect for doubleclique

 void Window::createFilesTable()
     filesTable = new QTableWidget(0, 2);
     QStringList labels;
     labels << tr("File Name") << tr("Size");
     filesTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
     filesTable->setShowGrid( true );
     // try to connect our signal to a slot --- this works ok -
2007-11-23 JK
     connect( filesTable, SIGNAL( cellActivated( int, int ) ),
              this, SLOT( showSelectedRow( int, int ) ),
Qt::DirectConnection ) ;

// this is my new slot ... as described above ...

void Window::showSelectedRow( int row, int column ) // this has problems
to show widgetItem in cout!!
    QDataStream out ;         // in order to receive the Item-Data (do I
have to out.open() ???)

    QTableWidgetItem *fileNameItem = new QTableWidgetItem( "ABC",
Qt::ItemIsSelectable ) ;

    QVariant fileName ;       // I am really unsure whether this is the
correct way here!!!

    row = row ; column = column ;
#ifdef TEST_ME
    std::cout << "\nRow nr." << row << " Column Nr.: "<< column << "\n"
<< endl ;
     // here we find in column 0 our filename
    fileNameItem = filesTable->item( row, 0 ) ;
    fileName = fileNameItem->data( Qt::DisplayRole ) ;
    //fileNameItem->write( out ) ;
    out << ( out, fileNameItem ) ;
#ifdef TEST_ME   // here we crash!!
    std::cout << "\nFileNameItem" << &out << "\n" << endl ;


To unsubscribe - send a mail to [email protected] with 
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/

Hi Joerg,

Just a general hint here...

I have faced a similar problem before and it was due to 2 things:

1. I tried to extract data from an uninitialized QTableWidgetItem.
2. I was extracting data from the same QTableWidgetItem. You should populate the QTableWidget with "new" QTableWidgetItem objects, not with the same one.

Hope this helps,

Kavindra Palaraja - kdpalara at trolltech.com
Trolltech ASA - Sandakerveien 116, NO-0484 Oslo, Norway

To unsubscribe - send a mail to [email protected] with 
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>