Results 1 to 2 of 2

Thread: segmentation fault when function from MainWindow is running

  1. #1
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default segmentation fault when function from MainWindow is running

    Qt Code:
    1. void MainWindow::change_gui_after_downloading(int value){
    2. if(value){
    3. ui->actionPc->setEnabled(false); //error here
    4. }
    5. else{
    6. ui->actionPc->setEnabled(true); //error here
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    and method in another class

    Qt Code:
    1. void download::access_to_gui(){
    2. MainWindow* pointer
    3. if(this->download_value)
    4. pointer->change_gui_after_downloading(1);
    5. else
    6. pointer->change_gui_after_downloading(0);
    7. }
    To copy to clipboard, switch view to plain text mode 

    When I create new object for MainWindow class in download class I get "QWidget: Must construct a QApplication before a QPaintDevice", when I create pointer for MainWindow I get "Segmentation fault" in change_gui_after_downloading(int) function.
    When I run change_gui_after_downloading(int) directly in MainWindow its working.
    Last edited by darkrptyp; 8th January 2012 at 11:14. Reason: spelling corrections

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: segmentation fault when function from MainWindow is running

    You need to pass a pointer of your actual main window to the class download. Otherwise you deal with 0 pointers or with different main windows. (Basic C++ and has nothing to do with Qt!)

    Alternatively (when download is created in MainWindow) you can use signal and slots.

Similar Threads

  1. How to hide from taskbar a form showed form mainwindow
    By tonnot in forum Qt Programming
    Replies: 1
    Last Post: 10th February 2011, 14:36
  2. Segmentation fault whilst running QtLocation app
    By Ereb in forum Qt Programming
    Replies: 7
    Last Post: 9th December 2010, 10:32
  3. Segmentation Fault
    By Krish_ng in forum Qt Programming
    Replies: 8
    Last Post: 7th August 2007, 10:49
  4. Segmentation fault running any QT4 executables
    By jellis in forum Installation and Deployment
    Replies: 7
    Last Post: 19th May 2007, 16:35
  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.