Qt-interest Archive, November 2007
QTableWidget-Problem (any comments?)
Message 1 in thread
Hello,
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
=======================================00
// this code snippet is from Trolltech:
QComboBox *Window::createComboBox(const QString &text)
{
QComboBox *comboBox = new QComboBox;
comboBox->setEditable(true);
comboBox->addItem(text);
comboBox->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Preferred);
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->setHorizontalHeaderLabels(labels);
filesTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
filesTable->verticalHeader()->hide();
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 ;
#endif
// 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 ;
#endif
}
=========================================
--
[ signature omitted ]
Message 2 in thread
Ionathan wrote:
> Hello,
>
> 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
>
> =======================================00
> // this code snippet is from Trolltech:
>
> QComboBox *Window::createComboBox(const QString &text)
> {
> QComboBox *comboBox = new QComboBox;
> comboBox->setEditable(true);
> comboBox->addItem(text);
> comboBox->setSizePolicy(QSizePolicy::Expanding,
> QSizePolicy::Preferred);
> 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->setHorizontalHeaderLabels(labels);
> filesTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
> filesTable->verticalHeader()->hide();
> 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 ;
> #endif
> // 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 ;
> #endif
> }
>
> =========================================
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
[snip...]
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,
K.
--
[ signature omitted ]
Message 3 in thread
...snip ...
>> out << ( out, fileNameItem ) ;
>> #ifdef TEST_ME // here we crash!!
>> std::cout << "\nFileNameItem" << &out << "\n" << endl ;
>> #endif
>> }
>
thanks,
> 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.
QTableWidgetItem is filled with data (see example of Trolltech)
> 2. I was extracting data from the same QTableWidgetItem. You should
> populate the QTableWidget with "new" QTableWidgetItem objects, not
> with the same one.
>
see above ...
> Hope this helps,
thanks for the hints ... J.
--
[ signature omitted ]
Message 4 in thread
Ionathan wrote:
> I am porting an application from qt3 to qt4 /under Suse Linux
> 10.2/. The
> tool qt3to4 did not work correctly.
Yeah, well, qt3to4 is only a helper, which simplifies things.
Complex programs won't running be correctly just using qt3to4.
However, i found it to be a time saver on many of my files.
> 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.
Maybe this helps?
http://doc.trolltech.com/4.3/qdatastream.html#QDataStream
I'm not sure what you're trying to achieve here. Do you want to extract
a string from the QVariant?
did you notice QVariant::toString()?
Cheers,
Peter
--
[ signature omitted ]
Message 5 in thread
Peter Prade schrieb:
> Ionathan wrote:
>
>> I am porting an application from qt3 to qt4 /under Suse Linux
>> 10.2/. The
>> tool qt3to4 did not work correctly.
>>
> Yeah, well, qt3to4 is only a helper, which simplifies things.
> Complex programs won't running be correctly just using qt3to4.
> However, i found it to be a time saver on many of my files.
>
>
>> 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.
>>
>
> Maybe this helps?
> http://doc.trolltech.com/4.3/qdatastream.html#QDataStream
>
> I'm not sure what you're trying to achieve here. Do you want to extract
> a string from the QVariant?
> did you notice QVariant::toString()?
>
> Cheers,
> Peter
>
thanks for the two advices. I will investigate ... will come later when
further questions on that topic! I also will investigate
QAbstractItemModel ... this seems to come close to my ideas ... Jörg
--
[ signature omitted ]