Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 48

Thread: Program crashes (SIGSEGV)

  1. #21
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes (SIGSEGV)

    Qt Code:
    1. QString version = "0.0.1 pre-alpha";
    2.  
    3. debugger *debug = new debugger("QQMsn_debug",version,true);
    4. cmsn *msn = new cmsn();
    5. Window_Login *window_login = 0;
    6. Window_Login_Busy *login_busy = 0;
    To copy to clipboard, switch view to plain text mode 

    Why do you create those objects like that? I believe there is something drawing you back to C .

    Instead of:
    Qt Code:
    1. QString version = "0.0.1 pre-alpha";
    To copy to clipboard, switch view to plain text mode 
    I suggest using:
    Qt Code:
    1. #define VERSION "0.0.1 pre-alpha"
    To copy to clipboard, switch view to plain text mode 

    Regarding the other static objects - you delete them in main .
    A really "static desing" would have supposed to implement something like AllocateObject ( called before main ) and ReleaseObject( called after main ).

    So, I suggest dragging the statics in main, after the QApplication is created, because I don't see any reason why you should keep them there.

    As for the segfault, as jacek said you most likely have a QSslSocket in an unallocated QMsn object ( from what I have seen in your code ).

  2. #22
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes (SIGSEGV)

    @wysota:

    1) What do you mean? I include and inheritance QObject in the classes... Can you explain (with an example?)?

    @marcel:

    2) How can I read the version? When I do this:

    Qt Code:
    1. setData("File generated by QQMsn " + VERSION);
    To copy to clipboard, switch view to plain text mode 

    (debugger.cpp)

    It doesn't work (VERSION not declared). How can I read it? Can you give a little example?

    3) Which thing do I still have to delete in main? Do you mean this:

    Qt Code:
    1. debugger *debug = new debugger("QQMsn_debug",true);
    2. cmsn *msn = new cmsn();
    3. Window_Login *window_login = 0;
    4. Window_Login_Busy *login_busy = 0;
    To copy to clipboard, switch view to plain text mode 

    ?

    But when I put these in main, I can't use extern in other files... Can you give an example?
    Using Qt version 4.3.0

  3. #23
    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: Program crashes (SIGSEGV)

    Quote Originally Posted by Voldemort View Post
    @wysota:

    1) What do you mean? I include and inheritance QObject in the classes... Can you explain (with an example?)?
    From what I understand you have a declaration like the following somewhere:

    Qt Code:
    1. extern SomeClass obj;
    To copy to clipboard, switch view to plain text mode 

    where SomeClass inherits QObject. So I suggest to use a pointer to the object instead of the object itself, so that you can create the object and assign it to the pointer after the application object is created.

  4. #24
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes (SIGSEGV)

    Quote Originally Posted by wysota View Post
    From what I understand you have a declaration like the following somewhere:

    Qt Code:
    1. extern SomeClass obj;
    To copy to clipboard, switch view to plain text mode 
    where SomeClass inherits QObject. So I suggest to use a pointer to the object instead of the object itself, so that you can create the object and assign it to the pointer after the application object is created.
    I understand a bit what you meaning, but not everything. Can you give an example?
    Using Qt version 4.3.0

  5. #25
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes (SIGSEGV)

    Have you thought about applying the singleton pattern?
    This means that your static objects will have something like a static GetInstance method that will return a pointer to the single instance (static,also ).

    There will be no need to use "extern", just call GetInstance wherever you need it ( but make sure to include the necessary files ).

    Regards

  6. #26
    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: Program crashes (SIGSEGV)

    I second what Marcel says. I'd even suggest subclassing QApplication and putting your object as a member of the application.

    Qt Code:
    1. class MyApp : public QApplication{
    2. public:
    3. MyApp(int a, char **b) : QApplication(a,b){
    4. m_x = new X(this);
    5. }
    6. X *x() const { return m_x; }
    7. private:
    8. X *m_x;
    9. };
    To copy to clipboard, switch view to plain text mode 

    A redefinition of qApp might also come in handy:
    Qt Code:
    1. #ifdef qApp
    2. #undef qApp
    3. #endif
    4. #define qApp static_cast<MyApp*>(QCoreApplication::instance())
    To copy to clipboard, switch view to plain text mode 

  7. #27
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes (SIGSEGV)

    Quote Originally Posted by wysota View Post
    I second what Marcel says. I'd even suggest subclassing QApplication and putting your object as a member of the application.

    Qt Code:
    1. class MyApp : public QApplication{
    2. public:
    3. MyApp(int a, char **b) : QApplication(a,b){
    4. m_x = new X(this);
    5. }
    6. X *x() const { return m_x; }
    7. private:
    8. X *m_x;
    9. };
    To copy to clipboard, switch view to plain text mode 
    A redefinition of qApp might also come in handy:
    Qt Code:
    1. #ifdef qApp
    2. #undef qApp
    3. #endif
    4. #define qApp static_cast<MyApp*>(QCoreApplication::instance())
    To copy to clipboard, switch view to plain text mode 
    Yes. Now he won't even need to include additional files because there will be qApp.

    Regards

  8. #28
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes (SIGSEGV)

    I understand what you mean. But I have questions:

    Qt Code:
    1. #ifdef qApp
    2. #undef qApp
    3. #endif
    4. #define qApp static_cast<MyApp*>(QCoreApplication::instance())
    To copy to clipboard, switch view to plain text mode 
    1) Where do I have to put this part? Every file? Just in the class file? Somewhere else?

    2) With that code I have to include some classes I use (the part above my main function in main.cpp)?

    3) Do I have to instantiate the class in all files or just in the main function? Or does it work in another way?

    4) Can I put the delete lines (now at the bottom of my main function in main.cpp) in the destructor of the class?
    Last edited by Voldemort; 16th May 2007 at 22:07.
    Using Qt version 4.3.0

  9. #29
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes (SIGSEGV)

    1. In the source file in which you will implement your subclass of QApplication.
    2. Only your QApplication class.
    3. Just the main function.
    4. Yes, if they will be the members of your custom QApplication, then you can put them in its destructor.

    Regards

  10. #30
    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: Program crashes (SIGSEGV)

    Quote Originally Posted by marcel View Post
    1. In the source file in which you will implement your subclass of QApplication.
    Header file, to be exact.

  11. #31
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes (SIGSEGV)

    I've tried to make such a class (source is in the attachment), but I get these errors:

    /home/quinten/QQMsn_test/src/QQMsnApplication.h: In constructor ‘QQMsnApplication::QQMsnApplication(int, char**)’:
    /home/quinten/QQMsn_test/src/QQMsnApplication.h:31: error: expected `{' at end of input
    /home/quinten/QQMsn_test/src/main.cpp: In function ‘int main(int, char**)’:
    /home/quinten/QQMsn_test/src/main.cpp:35: error: ‘arg’ was not declared in this scope
    /home/quinten/QQMsn_test/src/main.cpp:37: error: invalid use of member (did you forget the ‘&’ ?)
    /home/quinten/QQMsn_test/src/main.cpp:37: error: base operand of ‘->’ is not a pointer
    /home/quinten/QQMsn_test/src/main.cpp:38: error: invalid use of member (did you forget the ‘&’ ?)
    /home/quinten/QQMsn_test/src/main.cpp:38: error: base operand of ‘->’ is not a pointer
    make[2]: *** [CMakeFiles/QQMsn.dir/src/main.o] Fout 1
    make[1]: *** [CMakeFiles/QQMsn.dir/all] Fout 2
    make: *** [all] Fout 2
    Why? What do I wrong?
    Attached Files Attached Files
    Using Qt version 4.3.0

  12. #32
    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: Program crashes (SIGSEGV)

    In header file this:
    Qt Code:
    1. QQMsnApplication(int a, char **b) : QApplication(a,b);
    To copy to clipboard, switch view to plain text mode 
    should be like this:
    Qt Code:
    1. QQMsnApplication(int a, char **b);
    To copy to clipboard, switch view to plain text mode 

  13. #33
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes (SIGSEGV)

    That solves some errors, but these are still present:

    /home/quinten/QQMsn_test/src/main.cpp: In function ‘int main(int, char**)’:
    /home/quinten/QQMsn_test/src/main.cpp:35: error: ‘arg’ was not declared in this scope
    /home/quinten/QQMsn_test/src/main.cpp:37: error: ‘window_login’ was not declared in this scope
    make[2]: *** [CMakeFiles/QQMsn.dir/src/main.o] Fout 1
    make[1]: *** [CMakeFiles/QQMsn.dir/all] Fout 2
    make: *** [all] Fout 2
    What is the bug?
    Using Qt version 4.3.0

  14. #34
    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: Program crashes (SIGSEGV)

    "‘arg’ was not declared in this scope" - should probably be "argc" or "argv".

  15. #35
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes (SIGSEGV)

    You have to use the members from QMSNApplication, namely:
    Qt Code:
    1. m_window_login = new Window_Login();
    2. m_login_busy = new Window_Login_Busy();
    To copy to clipboard, switch view to plain text mode 
    I didn't look too much at the code, but if you don't have accessors for them, then create them.

    As for the "arg" error, make sure that the parameter names of main coincide with the parameters of your qmsnapplication - argc and argv.

    Regards

  16. #36
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes (SIGSEGV)

    Actually, I looked better now.

    You already have accessors. Then why not use them?
    I am talking about:
    Qt Code:
    1. public:
    2. QQMsnApplication(int a, char **b) : QApplication(a,b);
    3. ~QQMsnApplication();
    4. debugger *debug();
    5. cmsn *msn();
    6. Window_Login *window_login();
    7. Window_Login_Busy *login_busy();
    To copy to clipboard, switch view to plain text mode 

    Use them in main.
    Qt Code:
    1. QQMsnApp.window_login()->show_start();
    2. QQMsnApp.window_login()->show();
    To copy to clipboard, switch view to plain text mode 

  17. #37
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes (SIGSEGV)

    1) I've changed that, but now I have errors in other classes (in window_login.cpp & window_login.h), they complain ‘QQMsnApp’ was not declared. How do I resolve this?

    2) Isn't there an option that I simply can do this:

    Qt Code:
    1. window_login()->show_start();
    To copy to clipboard, switch view to plain text mode 
    with the current code. Or will I always have to put QQMsnApp. before it?

    3)
    Qt Code:
    1. #ifdef qApp
    2. #undef qApp
    3. #endif
    4. #define qApp static_cast<MyApp*>(QCoreApplication::instance())
    To copy to clipboard, switch view to plain text mode 

    What do I have to do with these lines? Why should I add them?
    Using Qt version 4.3.0

  18. #38
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes (SIGSEGV)

    2) No, since now they are objects of QMSNApp. I don't see any problem with this.

    3. You need that for 1) and 2).
    Wherever you need QMsnApp use qApp instead and access QMsn and the other memebers with the functions you created.

    Regards

  19. #39
    Join Date
    May 2007
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes (SIGSEGV)

    It doesn't work, I put this at the top of the header file:

    Qt Code:
    1. #ifdef qApp
    2. #undef qApp
    3. #endif
    4. #define qApp static_cast<QQMsnApp>(QCoreApplication::instance())
    To copy to clipboard, switch view to plain text mode 

    And in the function StartLogin() I use this:

    Qt Code:
    1. //Variablen goed zetten
    2. qApp.cmsn()->setMail(mail->text());
    3. qApp.cmsn()->setPass(pass->text());
    4.  
    5. //Toon het nieuwe venster (login_busy)
    6. if(!started_login_busy)
    7. {
    8. qApp.login_busy()->show_start();
    9. started_login_busy = true;
    10. }
    11.  
    12. qApp.login_busy()->show();
    13.  
    14. //De functie aanroepen die de socket opent en het eerst commando zend
    15. qApp.cmsn()->StartLogin();
    To copy to clipboard, switch view to plain text mode 

    But it doesn't work, I get this:

    /home/quinten/QQMsn_test/src/window_login.cpp: In member function ‘void Window_Login::startLogin()’:
    /home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected type-specifier before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected `>' before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected `(' before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:82: error: ‘QQMsnApp’ was not declared in this scope
    /home/quinten/QQMsn_test/src/window_login.cpp:82: error: ‘QCoreApplication’ has not been declared
    /home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected `)' before ‘;’ token
    /home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected type-specifier before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected `>' before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected `(' before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:83: error: ‘QCoreApplication’ has not been declared
    /home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected `)' before ‘;’ token
    /home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected type-specifier before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected `>' before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected `(' before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:88: error: ‘QCoreApplication’ has not been declared
    /home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected `)' before ‘;’ token
    /home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected type-specifier before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected `>' before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected `(' before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:92: error: ‘QCoreApplication’ has not been declared
    /home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected `)' before ‘;’ token
    /home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected type-specifier before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected `>' before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected `(' before ‘QQMsnApp’
    /home/quinten/QQMsn_test/src/window_login.cpp:95: error: ‘QCoreApplication’ has not been declared
    /home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected `)' before ‘;’ token
    make[2]: *** [CMakeFiles/QQMsn.dir/src/window_login.o] Fout 1
    make[1]: *** [CMakeFiles/QQMsn.dir/all] Fout 2
    make: *** [all] Fout 2
    What is now wrong?
    Using Qt version 4.3.0

  20. #40
    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: Program crashes (SIGSEGV)

    Compare my define and yours. They differ by a one very important character. Also make sure header files defining classes you reference are always included.

Similar Threads

  1. Porting my program to another windows machine !
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 14th March 2007, 07:46
  2. QT Program debug,GDB on Linux
    By darpan in forum General Programming
    Replies: 1
    Last Post: 26th January 2007, 23:02
  3. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 05:19
  4. Enter key causing program to exit
    By welby in forum Qt Programming
    Replies: 2
    Last Post: 9th March 2006, 17:11
  5. Reading from TCP Socket crashes program
    By OnionRingOfDoom in forum Qt Programming
    Replies: 26
    Last Post: 27th January 2006, 20: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.