SLOT problem / C++
SLOT problem / C++
我正试图找出这个错误。我用Qt Creator做了一个简单的应用程序。
我有三个按钮,其中两个没有启用。然后,当按下第一个按钮时,我想让它们可见,但当我按下按钮时,出现了窗口错误:"程序停止工作"。该程序编译并执行其他所有操作。
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);
}
这就是密码。
问题是,您在构造函数中重新声明dealButton
和其他函数(或者显示new
调用的任何函数)。
你应该在你的类中定义:
private: // probably
QPushButton *dealButton;
在您的构造函数或gui初始化代码中:
dealButton = new QPushButton(...); // note: not QPushButton *dealButton = ...
您现在所拥有的是创建一个名为dealButton
的新变量,该变量是该作用域(函数)的本地变量。该变量隐藏(屏蔽)了类的成员。
相关文章:
- 无法让 Assimp 在 Windows " linker problem" 上运行?(与2019年相比)
- C++ Winsock unicode problem
- QT QStackedLayout problem
- Problem with Android ndk
- OpenGL SuperBible header problem
- WaitForSingleObject problem
- Anderson tree problem
- for_each C++ Problem
- Getline problem
- CDialog ShowWindow problem
- SLOT problem / C++
- BitBlt Problem GDI
- Problem with C# COM
- eof problem c++
- Problem with Euler 27