Results 1 to 5 of 5

Thread: segmentation fault!!

  1. #1
    Join Date
    Jan 2010
    Posts
    37
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default segmentation fault!!

    Hi guys,

    I am using old version of Qt which comes with the Friendly arm device for embedded development.
    It consists of Qtopia 2.2.0 with Qt2 designer.

    I prepared a small application for testing using a QListView. I drew ListView widget on my form which i named ListView and named ny UI file as myapp_base.ui.

    In my header file i wrote-

    Qt Code:
    1. #ifndef MYAPP_H
    2. #define MYAPP_H
    3.  
    4. #include "myapp_base.h"
    5.  
    6. class MyApp : public MyAppBase
    7. {
    8. public:
    9. MyApp(QWidget *parent=0,const char *name=0, WFlags fl=0);
    10. ~MyApp();
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    My implementation file is following-

    Qt Code:
    1. #include "myapp.h"
    2. #include <qlistview.h>
    3.  
    4. MyApp::MyApp(QWidget *parent, const char *name,WFlags fl):
    5. MyAppBase(parent,name,fl)
    6. {
    7. QListViewItem *newItem;
    8. newItem->setText(0,"newItem");
    9. ListView->insertItem(newItem);
    10. }
    11.  
    12. MyApp::~MyApp()
    13. {
    14. }
    To copy to clipboard, switch view to plain text mode 

    And my main file is-

    Qt Code:
    1. #include "myapp.h"
    2. #include <qapplication.h>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc,argv);
    7. MyApp *obj;
    8. obj->show();
    9.  
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    My code gets compiled successfully but gives a runtime segmentation fault. What is the problem??

  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: segmentation fault!!

    You didn't create the item, just a pointer to it.
    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
    Jan 2010
    Posts
    37
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: segmentation fault!!

    Ok, But then when i wrote main like this-

    Qt Code:
    1. #include "myapp.h"
    2. #include <qapplication.h>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc,argv);
    7. MyApp obj;
    8. obj.show();
    9.  
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    It gave me following error-

    error main.cpp.7.there is no call for MyApp::MyApp()
    candidates for the call are MyApp::MyApp(QWidget *parent,const char *name, WFlags fl);
    candidates to the call are MyApp::MyApp(const MyApp&);

    Also when i tried this..

    Qt Code:
    1. MyApp obj=new MyApp;
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. MyApp obj= new MyApp();
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. MyApp obj=new MyApp(ListView,"myapp");
    To copy to clipboard, switch view to plain text mode 

    it gave the same error!!!!

    what to do???
    Last edited by wysota; 24th March 2010 at 11:54.

  4. #4
    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!!

    The error was not in main() but in MyApp::MyApp().

    Please do yourself a favour and refresh your C++ knowledge.
    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.


  5. #5
    Join Date
    Jan 2010
    Posts
    37
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: segmentation fault!!

    Thanks very much...problem solved!!!

Similar Threads

  1. Segmentation Fault
    By freekill in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2010, 15:31
  2. Segmentation fault
    By MarkoSan in forum Qt Programming
    Replies: 23
    Last Post: 19th October 2008, 22:40
  3. segmentation fault
    By dreamer in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2008, 07:48
  4. segmentation fault
    By mattia in forum Newbie
    Replies: 22
    Last Post: 7th November 2007, 10:37
  5. segmentation fault
    By shamik in forum Qt Programming
    Replies: 3
    Last Post: 24th November 2006, 07:33

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.