Results 1 to 2 of 2

Thread: segfault

  1. #1
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    4

    Default segfault

    Hello!
    I have got a class SmsGui which contains 2 forms generated by qtdesigner: mainWindow and loginWindow. Firstly when program runs, mainWidnow is created and shown. When user presses Ok on mainWindow, loginWindow is created and shown. And here are 2 situations: in first situation I do:
    Qt Code:
    1. connect(loginWindow->cancelButton, SIGNAL(clicked()), loginWindow, SLOT(close()));
    To copy to clipboard, switch view to plain text mode 
    And loginDialog closes normally. But in a secod situation I call loginDialog->close() manually.
    Qt Code:
    1. connect(loginWindow->cancelButton, SIGNAL(clicked()), this, SLOT(kill()));
    2.  
    3. void SmsGui::kill()
    4. {
    5. loginDialog->close();
    6. }
    To copy to clipboard, switch view to plain text mode 
    And this gives me a segfault. Why? I just call the same function but in 2 different ways, so why it gives me a segfault?
    Backtrace:
    Qt Code:
    1. Program received signal SIGSEGV, Segmentation fault.
    2. [Switching to Thread -1223948608 (LWP 25558)]
    3. 0x0804d9a4 in SmsGui::kill (this=0x8061670) at sms_gui.cpp:125
    4. 125 loginDialog->close();
    5. (gdb) backtrace
    6. #0 0x0804d9a4 in SmsGui::kill (this=0x8061670)
    7. at sms_gui.cpp:125
    8.  
    9. #1 0x0804d995 in SmsGui::clickedLoginOk (this=0x8061670)
    10. at sms_gui.cpp:120
    11. #2 0x08050d14 in SmsGui::qt_metacall (this=0x8061670,
    12. _c=QMetaObject::InvokeMetaMethod, _id=5, _a=0xbfa59790)
    13. at moc_sms_gui.cpp:83
    14. #3 0xb746132c in QMetaObject::activate ()
    15. from /usr/lib/qt4/libQtCore_debug.so.4
    16. #4 0xb746157e in QMetaObject::activate ()
    17. from /usr/lib/qt4/libQtCore_debug.so.4
    18. #5 0xb7e011f6 in QAbstractButton::clicked ()
    19. from /usr/lib/qt4/libQtGui_debug.so.4
    20. #6 0xb7c66455 in QAbstractButtonPrivate::click ()
    21. from /usr/lib/qt4/libQtGui_debug.so.4
    22. #7 0xb7c67779 in QAbstractButton::mouseReleaseEvent ()
    23. from /usr/lib/qt4/libQtGui_debug.so.4
    24. #8 0xb7a3879d in QWidget::event ()
    25. from /usr/lib/qt4/libQtGui_debug.so.4
    26. #9 0xb7c6761b in QAbstractButton::event ()
    27. from /usr/lib/qt4/libQtGui_debug.so.4
    28. #10 0xb7ce0d52 in QPushButton::event ()
    29. from /usr/lib/qt4/libQtGui_debug.so.4
    30. #11 0xb79ecea7 in QApplicationPrivate::notify_helper ()
    To copy to clipboard, switch view to plain text mode 

    Header file:
    Qt Code:
    1. #ifndef SMS_GUI_H
    2. #define SMS_GUI_H
    3.  
    4. #include <QDialog>
    5. #include "ui_main_window.h"
    6. #include "ui_login_dialog.h"
    7. #include "types.h"
    8.  
    9. class SmsGui : public QObject
    10.  
    11. {
    12.  
    13. Q_OBJECT
    14.  
    15. public:
    16. QString username, password, number, message;
    17. bool limitCheck;
    18. unsigned short int port;
    19. void destroy();
    20. void showMainWindow();
    21.  
    22. void connectSlots();
    23. void disconnectSlots();
    24. void setMiastoPlusaParameters();
    25. void showLoginDialog();
    26. Ui_mainWindow *mainWindow;
    27. QDialog *mainDialog;
    28.  
    29. Ui_loginDialog *loginWindow;
    30. QDialog *loginDialog;
    31.  
    32.  
    33.  
    34. public slots:
    35. void enableSendButtonText();
    36. void enableSendButtonLine(const QString &newText);
    37. void resetAll();
    38. void currentIndexChanged(int index);
    39. void clickedLoginOk();
    40. void clickedSend();
    41. void clickedLoginCancel();
    42.  
    43. void closeMainWindow();
    44. void kill();
    45. public:
    46. SmsGui();
    47. ~SmsGui();
    48.  
    49. signals:
    50. void readyToSend(network);
    51.  
    52.  
    53. };
    To copy to clipboard, switch view to plain text mode 

    source:
    Qt Code:
    1. #include "sms_gui.h"
    2.  
    3. SmsGui::SmsGui()
    4. {
    5. showMainWindow();
    6. connectSlots();
    7. }
    8.  
    9. SmsGui::~SmsGui()
    10. {
    11. closeMainWindow();
    12. }
    13.  
    14. void SmsGui::showMainWindow()
    15. {
    16. mainDialog = new QDialog;
    17. mainWindow = new Ui_mainWindow;
    18. mainWindow->setupUi(mainDialog);
    19. mainDialog->show();
    20. }
    21.  
    22. void SmsGui::closeMainWindow()
    23. {
    24. mainDialog->reject();
    25. delete mainDialog;
    26. mainDialog = NULL;
    27. delete mainWindow;
    28. mainWindow = NULL;
    29. }
    30.  
    31. void SmsGui::connectSlots()
    32. {
    33. connect(mainWindow->okButton, SIGNAL(clicked()), this, SLOT(clickedSend()));
    34. }
    35.  
    36.  
    37. void SmsGui::clickedSend()
    38. {
    39. //mainDialog->close();
    40. switch(mainWindow->comboBox->currentIndex())
    41. {
    42. case 0: setMiastoPlusaParameters(); return;
    43. case 1: /*setPlusWWWParameters();*/ return;
    44. default: return;
    45. }
    46. }
    47.  
    48. void SmsGui::showLoginDialog()
    49. {
    50. QDialog *loginDialog = new QDialog;
    51. loginWindow = new Ui_loginDialog;
    52. loginWindow->setupUi(loginDialog);
    53. connect(loginWindow->okButton, SIGNAL(clicked()), this, SLOT(clickedLoginOk()));
    54. connect(loginWindow->cancelButton, SIGNAL(clicked()), this, SLOT(clickedLoginCancel()));
    55. loginDialog->show();
    56. }
    57.  
    58. void SmsGui::clickedLoginOk()
    59. {
    60.  
    61. kill();
    62. }
    63.  
    64. void SmsGui::kill()
    65. {
    66. loginDialog->close();
    67. }
    68.  
    69.  
    70. void SmsGui::clickedLoginCancel()
    71. {
    72. loginDialog->close();
    73. }
    74.  
    75. void SmsGui::setMiastoPlusaParameters()
    76. {
    77. showLoginDialog();
    78. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    4

    Default Re: segfault

    Problem solved. loginDialog was overriden loclly, then used uninitialized

Similar Threads

  1. segfault in qtfontdatabase_x11.cpp
    By e8johan in forum Installation and Deployment
    Replies: 3
    Last Post: 18th April 2006, 07:07
  2. Why does setTextColor() cause a segfault?
    By johnny_sparx in forum Qt Programming
    Replies: 1
    Last Post: 1st April 2006, 16:58
  3. segfault on qtextstream
    By patcito in forum Qt Programming
    Replies: 13
    Last Post: 26th February 2006, 13:10
  4. Replies: 10
    Last Post: 10th February 2006, 00:15

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.