开发者

SLOT problem / C++

Im trying to figure this error out. I have a simple application made with Qt Creator.

I have three buttons and 2 of them are not enabled. Then when push the first button i want to make them visible, but when i push the button, windows error occures : "program stopped working". the program compiles and does everything else.

QPushButton *dealButton = new QPushButton(tr("Deal cards"));
dealButton->show();

QPushButton *hitButton = new QPushButton(tr("HIT"));
hitButton->show();
hitButton->setEnabled(false);

QPushButton *standButton = new QPushButton(tr("STAND"));
standButton->show();
standButton->setEnabled(false);

...
connect(dealButton, SIGNAL(clicked()), this, SLOT(dealCards()));

...
void MainWindow::dealCards()
{
hitButton->setEnabled(true);
standButton->setEnabled(true);
}

t开发者_开发问答hats the code.


The problem is that you are re-declaring dealButton and the others in your constructor (or whatever function it is that has the new calls you're showing).

You should have in your class definition:

private: // probably
  QPushButton *dealButton;

And in your constructor or gui init code:

dealButton = new QPushButton(...); // note: not QPushButton *dealButton = ...

What you have now is creating a new variable called dealButton that is local to that scope (function). That variable is hiding (masking) the class's member.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜