PDA

View Full Version : Extracting text from QTableWidgetItem



bizmopeen
31st August 2009, 20:40
Hello, all;

I’d appreciate some assistance in being able to extract text from a QTableWidgetItem. I’ve tried using the .text() command, but I have problems getting the text and passing it along no matter how I declare the object that I use to hold it. The object I seem to be having problems with is “displayText” below: I’ve tried declaring it as a pointer and a non-pointer, and the only way I can get this code to compile is by writing it this way (right now I’m using dummy text to try to get the program to work):


QTableWidget *listWidget = new QTableWidget(2,2,this);
QTableWidgetItem *newItem1 = new QTableWidgetItem(tr("Display Text 1"));
listWidget->setItem(0, 0, newItem1);
listWidget->hide();

QString displayText;

displayText = (*newItem1).text();

QLineEdit *textDisplay = new QLineEdit();
textDisplay->setStyleSheet(swQuad2_stylesheet);
textDisplay->setText(displayText);
textDisplay->setReadOnly(true);

QVBoxLayout *SWLayout = new QVBoxLayout;
SWLayout->addStretch(1);
SWLayout->addWidget(textDisplay);
SWLayout->addStretch(1);

However, even though the code does compile, I get the following errors when I run it:

Could not parse application stylesheet
Segmentation fault

Any suggestions? Thanks in advance.

wysota
31st August 2009, 21:35
Please provide a minimal compilable example reproducing the problem.

victor.fernandez
1st September 2009, 09:21
Did you try with displayText = newItem1->text(); ?

If you get a segmentation fault, some code and a backtrace would be helpful.

bizmopeen
1st September 2009, 17:28
Did you try with displayText = newItem1->text(); ?

If you get a segmentation fault, some code and a backtrace would be helpful.

Thanks, Victor. The backtrace led me to a different section of code which had been changed without my knowledge! Much appreciated.