質問

I am creating a popuo window that can change the message that shows. I have the next class

class NoPutPort : public QDialog, public Ui::NoPortPut
{
Q_OBJECT;
public:
  NoPutPort(QWidget *parent=0)  {
     setupUi(this);
}

~NoPutPort(void) {}

void putPort(QString a){
    ui.label_2->setText(a);
}

private:
Ui::NoPortPut ui;
};

The problem if when I call the method putPort, the application crash and I dont know why. If I put ui.label_2, it dont crash, but when I access to the object to modify it, it crash.

Anyone knows how can I modify the label correctly?

役に立ちましたか?

解決

You've messed up the code. It should be:

class NoPutPort : public QDialog
{
Q_OBJECT;
public:
  NoPutPort(QWidget *parent=0)  {
     ui.setupUi(this);
}

~NoPutPort(void) {}

void putPort(QString a){
    ui.label_2->setText(a);
}

private:
   Ui::NoPortPut ui;
};

XOR

class NoPutPort : public QDialog, public Ui::NoPortPut
{
Q_OBJECT;
public:
  NoPutPort(QWidget *parent=0)  {
     setupUi(this);
}

~NoPutPort(void) {}

void putPort(QString a){
    label_2->setText(a);
}
};
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top