Results 1 to 4 of 4

Thread: Extracting text from QTableWidgetItem

  1. #1
    Join Date
    Jul 2009
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Extracting text from QTableWidgetItem

    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):

    Qt Code:
    1. QTableWidget *listWidget = new QTableWidget(2,2,this);
    2. QTableWidgetItem *newItem1 = new QTableWidgetItem(tr("Display Text 1"));
    3. listWidget->setItem(0, 0, newItem1);
    4. listWidget->hide();
    5.  
    6. QString displayText;
    7.  
    8. displayText = (*newItem1).text();
    9.  
    10. QLineEdit *textDisplay = new QLineEdit();
    11. textDisplay->setStyleSheet(swQuad2_stylesheet);
    12. textDisplay->setText(displayText);
    13. textDisplay->setReadOnly(true);
    14.  
    15. QVBoxLayout *SWLayout = new QVBoxLayout;
    16. SWLayout->addStretch(1);
    17. SWLayout->addWidget(textDisplay);
    18. SWLayout->addStretch(1);
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by wysota; 31st August 2009 at 22:34. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Extracting text from QTableWidgetItem

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2008
    Posts
    98
    Thanks
    2
    Thanked 24 Times in 24 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extracting text from QTableWidgetItem

    Did you try with displayText = newItem1->text(); ?

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

  4. The following user says thank you to victor.fernandez for this useful post:

    bizmopeen (1st September 2009)

  5. #4
    Join Date
    Jul 2009
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Extracting text from QTableWidgetItem

    Quote Originally Posted by victor.fernandez View Post
    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.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. QTableWidgetItem Text Editing
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 03:23
  3. Extracting text from files (AKA I'm a newbie!)
    By mike phillips in forum Newbie
    Replies: 16
    Last Post: 30th January 2009, 18:27
  4. Setting a highlight text color for QTableWidgetItem
    By Hiba in forum Qt Programming
    Replies: 6
    Last Post: 14th December 2007, 11:51
  5. Auto text select in QTableWidgetItem
    By tstankey in forum Newbie
    Replies: 2
    Last Post: 5th October 2006, 21:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.