Results 1 to 6 of 6

Thread: Segmentation Fault when accesing more than once

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Segmentation Fault when accesing more than once

    OK i dont know if it is the hour or what but this lines cause the program to finish unexpectedly, only if the process is called more than once. I mean everything goes fine when i click the button for the first time but if I click it again bamm app exits:

    Qt Code:
    1. RandomInfo *randurl = new RandomInfo ();
    2. if (url.contains (QString ("ya_cerramos")))
    3. bg = QPixmap (url);
    4. else{
    5. bg = QPixmap (randurl->getRandomUrl ());
    6. }
    7. this->ui->label_imagen->setPixmap (bg);
    8. QStringList frase_autor = QStringList ();
    9. frase_autor = randurl->getFraseRandom ();
    To copy to clipboard, switch view to plain text mode 



    PS: this is the code of the method that returns the list, just in case:

    Qt Code:
    1. QStringList frase_autor;
    2. frase_autor << query->value (1).toString ().trimmed ()<< query->value (2).toString ().trimmed ();
    3. return frase_autor;
    To copy to clipboard, switch view to plain text mode 

    BTW i dont get any error while executing this, the list is returned...the problem is when I assign the return list to the list of the mainclass...
    Last edited by KillGabio; 11th February 2012 at 07:50.

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Segmentation Fault when accesing more than once

    First thing to do would obviously be to find out where is crashes...
    Success of all 'new's shoud always be checked. If the second time return null, of course the application crashes.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Segmentation Fault when accesing more than once

    Success of all 'new's shoud always be checked.
    C++ new either returns successfully with memory allocated or throws a bad_alloc exception which will generally terminate the program unless you have coded to catch it. Checking the return value is largely unneeded.

    KillGabio: If this is the same program you had the other day, where the ui was hacked about to replace the main window central widget, then my money is on the ui->label_imagen pointer being invalid the second time. Put:
    Qt Code:
    1. Q_ASSERTX(ui->label_imagen, "This code", "UI is mangled :(");
    To copy to clipboard, switch view to plain text mode 
    before line 8.

    BTW: Do you deallocate the RandomInfo object every time or are you leaking memory? Does this object need to be on the heap?

Similar Threads

  1. QWT - Segmentation Fault
    By Wojtek.wk in forum Newbie
    Replies: 0
    Last Post: 17th April 2010, 14:29
  2. segmentation fault
    By navid in forum Qt Programming
    Replies: 3
    Last Post: 20th December 2009, 11:40
  3. Segmentation fault
    By Schimanski in forum Qt Programming
    Replies: 20
    Last Post: 31st August 2009, 16:26
  4. Segmentation Fault?!
    By r07f1 in forum Newbie
    Replies: 2
    Last Post: 11th April 2008, 15:10
  5. Segmentation Fault
    By merry in forum General Programming
    Replies: 4
    Last Post: 12th March 2007, 04:08

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.