PDA

View Full Version : SLOT Crash



waynew
9th May 2009, 14:58
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!



#ifndef REMOTECONNECTION_H
#define REMOTECONNECTION_H

#include <QtGui/QDialog>
#include "ui_remoteconnection.h"

namespace Ui {
class RemoteConnection;
}

class RemoteConnection : public QDialog {
Q_OBJECT
Q_DISABLE_COPY(RemoteConnection)
public:
explicit RemoteConnection(QWidget *parent = 0);
virtual ~RemoteConnection();

protected:
virtual void changeEvent(QEvent *e);

private:
Ui::RemoteConnection *m_ui;

public slots:
void connecting();
};

#endif // REMOTECONNECTION_H


#include "remoteconnection.h"
#include "ui_remoteconnection.h"

RemoteConnection::RemoteConnection(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::RemoteConnection)
{
m_ui->setupUi(this);
m_ui->connectionStatus->setText("Not Connected"); // THIS DISPLAYS OK

connect(m_ui->pbConnect, SIGNAL(clicked()), this, SLOT(connecting()));

}

RemoteConnection::~RemoteConnection()
{
delete m_ui;
}

void RemoteConnection::connecting()
{
Ui_RemoteConnection rc;
rc.connectionStatus->setText("Trying"); // CRASHES HERE WHEN CONNECT BUTTON IS PUSHED
}

void RemoteConnection::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}

Boron
9th May 2009, 15:10
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");

waynew
9th May 2009, 15:19
Thanks Boron! Works fine now. :)
I'm trying to convert from Java and the structure differences are biting me!