Results 1 to 3 of 3

Thread: SLOT Crash

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default SLOT Crash

    This is probably very simple to solve but since I am a newbie to both C++ and QT, I just can't see it. main shows the remoteconnection form on startup and the text "Not Connected" displays in the line edit connectionStatus, no problem. When you push the button pbConnect which calls connecting() and tries to change the text, the application crashes.

    Any help is appreciated!

    Qt Code:
    1. #ifndef REMOTECONNECTION_H
    2. #define REMOTECONNECTION_H
    3.  
    4. #include <QtGui/QDialog>
    5. #include "ui_remoteconnection.h"
    6.  
    7. namespace Ui {
    8. class RemoteConnection;
    9. }
    10.  
    11. class RemoteConnection : public QDialog {
    12. Q_OBJECT
    13. Q_DISABLE_COPY(RemoteConnection)
    14. public:
    15. explicit RemoteConnection(QWidget *parent = 0);
    16. virtual ~RemoteConnection();
    17.  
    18. protected:
    19. virtual void changeEvent(QEvent *e);
    20.  
    21. private:
    22. Ui::RemoteConnection *m_ui;
    23.  
    24. public slots:
    25. void connecting();
    26. };
    27.  
    28. #endif // REMOTECONNECTION_H
    29.  
    30.  
    31. #include "remoteconnection.h"
    32. #include "ui_remoteconnection.h"
    33.  
    34. RemoteConnection::RemoteConnection(QWidget *parent) :
    35. QDialog(parent),
    36. m_ui(new Ui::RemoteConnection)
    37. {
    38. m_ui->setupUi(this);
    39. m_ui->connectionStatus->setText("Not Connected"); // THIS DISPLAYS OK
    40.  
    41. connect(m_ui->pbConnect, SIGNAL(clicked()), this, SLOT(connecting()));
    42.  
    43. }
    44.  
    45. RemoteConnection::~RemoteConnection()
    46. {
    47. delete m_ui;
    48. }
    49.  
    50. void RemoteConnection::connecting()
    51. {
    52. Ui_RemoteConnection rc;
    53. rc.connectionStatus->setText("Trying"); // CRASHES HERE WHEN CONNECT BUTTON IS PUSHED
    54. }
    55.  
    56. void RemoteConnection::changeEvent(QEvent *e)
    57. {
    58. QDialog::changeEvent(e);
    59. switch (e->type()) {
    60. case QEvent::LanguageChange:
    61. m_ui->retranslateUi(this);
    62. break;
    63. default:
    64. break;
    65. }
    66. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SLOT Crash

    Why do you create a new object of type Ui_RemoteConnection in connecting()?
    Your RemoteConnection object already has a user interface!

    Just call m_ui.connectionStatus->setText("Trying"); instead of rc.connectionStatus->setText("Trying");

  3. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SLOT Crash

    Thanks Boron! Works fine now.
    I'm trying to convert from Java and the structure differences are biting me!

Similar Threads

  1. How to declare SLOT as a parameter to member function?
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2018, 00:41
  2. Replies: 12
    Last Post: 18th September 2008, 15:04
  3. Problem When Creating my own Slot
    By Fatla in forum Qt Programming
    Replies: 12
    Last Post: 6th June 2008, 14:44
  4. Replies: 2
    Last Post: 23rd May 2008, 13:22

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.