Results 1 to 3 of 3

Thread: segmentation fault in accessing QString->text()

  1. #1
    Join Date
    May 2013
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default segmentation fault in accessing QString->text()

    hi

    I'm coding spreadsheet ... so i am using QTableWidget in my program
    I coded a func for saving table's items ...

    i have a structure here :
    Qt Code:
    1. struct cells
    2. {
    3. int r;
    4. int c;
    5. QString text;
    6. };
    To copy to clipboard, switch view to plain text mode 

    in this func I want to save items
    reads items ... copies data into a cells object :

    Qt Code:
    1. void MainWindow::on_save_clicked()
    2. {
    3. cells *temp;
    4. fstream file;
    5. file.open("test_3.txt",ios::out |ios::binary |ios::trunc);
    6. if(file)
    7. {
    8. for(int i=0;i<ui->tableWidget->columnCount();i++)
    9. for(int j=0;j<ui->tableWidget->rowCount()-1;j++)
    10. {
    11. temp=new cells;
    12. temp->c=i;
    13. temp->r=j;
    14. temp->text.append("ui->tableWidget->item(j,i)->text()");
    15. file.write(reinterpret_cast<char* >(temp),sizeof(cells));
    16. delete temp;
    17. }
    18. file.close();
    19. }
    20. else
    21. this->close();
    22.  
    23. }
    To copy to clipboard, switch view to plain text mode 

    my program stops working in this line and when i debug it , it shows me the "segmentation fault" from my OS , this line :
    Qt Code:
    1. temp->text.append("ui->tableWidget->item(j,i)->text()");
    To copy to clipboard, switch view to plain text mode 

    why ?
    what's it's problem with text function of QString class here ?

    thanks

  2. #2
    Join Date
    May 2013
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: segmentation fault in accessing QString->text()

    after testings , i got I have just access to item 0,0 function and when I want to have access to any other item , it stops working ...

    why ?

  3. #3
    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: segmentation fault in accessing QString->text()

    How is your question related to Qwt?
    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.


Similar Threads

  1. Replies: 2
    Last Post: 16th June 2010, 23:58
  2. Segmentation fault regarding QString in Qt/linux
    By payal in forum Qt Programming
    Replies: 14
    Last Post: 25th February 2010, 07:42
  3. Segmentation fault when creating new QString
    By di_zou in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2009, 18:07
  4. Segmentation Fault accessing QListWidget
    By ljshap in forum Newbie
    Replies: 2
    Last Post: 20th December 2008, 13:00
  5. Accessing child widgets Qtable cause segmentation fault?
    By yektaayduk in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2008, 18:55

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.