Results 1 to 6 of 6

Thread: Program crashes while trying to do a check in constructor

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Program crashes while trying to do a check in constructor

    Hi, I have 2 .ui files. One is the main and the other is the preferences window(this is actually a QDialog). In the constructor of the preferences window i have added this code to check if the second line of a file contains the char "1". Unfortunately then the program craches (this is the reason for sure, because when I comment this piece of source then it works fine...
    This is the source:
    Qt Code:
    1. char homee[150]="/home/";
    2. strcat(homee,py); //py is the current logged on user
    3. char otherr[100]="/.config/on_launch_enabled_options";
    4. strcat(homee,otherr);
    5. char line [ 128 ];
    6. int i;
    7. FILE *file = fopen ( homee, "r" );
    8. for ( i = 0; i < 1; ++i )
    9. {
    10. fgets ( line, sizeof line, file ); }
    11. fclose ( file );
    12. if(!strcmp (line,"1\n"))
    13. ui->checkminimizeonlaunch->setCheckState(Qt::Checked); else ui->checkminimizeonlaunch->setCheckState(Qt::Unchecked);
    To copy to clipboard, switch view to plain text mode 
    Thx for any replies.
    Notice that if I do the same thing in a Qt-console application it works fine
    (changing ui->checkminimizeonlaunch->setCheckState(Qt::Checked); else ui->checkminimizeonlaunch->setCheckState(Qt::Unchecked); to cout << "Strings Are similar\n"; )

    It crushes exactly at the point it says fgets ( line, sizeof line, file );
    Last edited by wysota; 1st September 2010 at 08:45.

Similar Threads

  1. qstringlist array crashes program
    By chrisb123 in forum Newbie
    Replies: 4
    Last Post: 23rd October 2009, 15:03
  2. Program crashes on creating new dialog
    By eekhoorn12 in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 11:52
  3. program crashes (QtTestRunner)
    By fmariusd in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2008, 09:27
  4. Program crashes (SIGSEGV)
    By Voldemort in forum Qt Programming
    Replies: 47
    Last Post: 21st May 2007, 20:09
  5. Reading from TCP Socket crashes program
    By OnionRingOfDoom in forum Qt Programming
    Replies: 26
    Last Post: 27th January 2006, 19:32

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.