В настоящее время я изучаю библиотеку QT, так как она кажется популярной библиотекой C ++ GUI.Раньше я использовал wxWidgets, которые в некоторых отношениях мне нравятся.Но я обнаружил, что QT дает мне больше возможностей в функциональности и в некоторых аспектах похож на wxWidgets.
В любом случае, я получаю странную ошибку (которая является названием этого поста), когда код не можетподключиться к моему слоту.Сначала я подумал, что я неправильно определяю свой слот.Затем оказывается, что один из объектов QPushButton мешает сигналу.
У меня есть объект Sequential Animation, где я беру две кнопки, заставляю их исчезать, а затем изменяю размер окна.Однако с этой ошибкой ни одна из анимаций не работает.Пока я не закомментирую свой объект QPushButton.Странно то, что этот объект еще не был выделен!Объект является указателем, и я не объявил его с новым, и я получаю эту ошибку.
Код прост, и я буду публиковать здесь файлы .h и .cpp.Я также буду отмечать, где возникает ошибка и где находятся объекты, которые вызывают у меня проблему:
Вот файл .h
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
QSequentialAnimationGroup *p_group;
// QParallelAnimationGroup *p_parallelGroup;
QPushButton *p_button;
QPushButton *p_anotherButton;
QPushButton *p_backButton; // This is the object that when commented out, removes the error
QPushButton *p_nextButton;
QPushButton *p_finishButton;
QPropertyAnimation *p_sizeAnimation;
QPropertyAnimation *p_fadeOut;
QGraphicsOpacityEffect *p_opacityEffect;
// QPushButton *p_backButton;
systemState p_GUIState;
void changeGUIState(systemState nextState);
private slots:
void handleButton();
void hideOpenButton();
void hideNewButton();
void hideBackButton();
void hideFinishButton();
void updateGUI();
};
А вот код в.файл cpp:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QHBoxLayout *startingLayout = new QHBoxLayout();
this->centralWidget()->setLayout(startingLayout);
this->statusBar()->setSizeGripEnabled(false);
this->statusBar()->setWindowTitle("Simulator");
p_button = new QPushButton("New", this);
p_anotherButton = new QPushButton("Open", this);
this->centralWidget()->layout()->addWidget(p_button);
this->centralWidget()->layout()->addWidget(p_anotherButton);
this->setWindowTitle("Omni-FEM");
// this->centralWidget()->layout()->children().at(1)
this->setFixedSize(this->minimumSize());
// p_anotherButton->setVisible(false);
// this->setFixedSize(this->cenOpentralWidget()->size());
connect(p_anotherButton, SIGNAL (released()), this, SLOT (handleButton()));
}
void MainWindow::changeGUIState(systemState nextState)
{
switch(nextState)
{
case systemState::PHYSICS_CHOOSING:
{
switch(p_GUIState)
{
case systemState::ON_START_UP_STATE:
{
this->setMaximumSize(QSize(1000, 1000));
if(p_group)
delete p_group;
p_group = new QSequentialAnimationGroup;
p_sizeAnimation = new QPropertyAnimation(this, "size");
p_sizeAnimation->setDuration(500);
p_sizeAnimation->setStartValue(this->size());
p_sizeAnimation->setEndValue(QSize(600, 600));
p_opacityEffect = new QGraphicsOpacityEffect(this);
QGraphicsOpacityEffect *test = new QGraphicsOpacityEffect(this);
p_button->setGraphicsEffect(test);
p_anotherButton->setGraphicsEffect(p_opacityEffect);
QPropertyAnimation *fadeTest = new QPropertyAnimation(test, "opacity");
p_fadeOut = new QPropertyAnimation(p_opacityEffect, "opacity");
p_fadeOut->setDuration(1000);
p_fadeOut->setStartValue(1);
p_fadeOut->setEndValue(0);
p_fadeOut->setEasingCurve(QEasingCurve::OutBack);
fadeTest = new QPropertyAnimation(test, "opacity");
fadeTest->setDuration(1000);
fadeTest->setStartValue(1);
fadeTest->setEndValue(0);
fadeTest->setEasingCurve(QEasingCurve::OutBack);
p_fadeOut->start();
fadeTest->start();
// p_group->addAnimation(p_fadeOut);
// p_group->addAnimation(fadeTest);
p_group->addAnimation(p_sizeAnimation);
connect(p_fadeOut, SIGNAL (finished()), this, SLOT (hideOpenButton()));
connect(fadeTest, SIGNAL (finished()), this, SLOT (hideNewButton()));
p_group->start();
}
break;
default:
break;
}
}
break;
default:
break;
}
p_GUIState = nextState;
connect(p_group, SIGNAL (finished()), this, SLOT (updateGUI())); // The Debugger throws the error on this line
}
// ----- Section is for Interrupts ------
void MainWindow::handleButton()
{
changeGUIState(systemState::PHYSICS_CHOOSING);
}
void MainWindow::hideNewButton()
{
p_button->setHidden(true);
}
void MainWindow::hideOpenButton()
{
p_anotherButton->setHidden(true);
}
void MainWindow::hideBackButton()
{
}
void MainWindow::hideFinishButton()
{
}
void MainWindow::updateGUI()
{
switch(p_GUIState)
{
case systemState::PHYSICS_CHOOSING:
if(!p_finishButton)
{
p_finishButton = new QPushButton("Finish", this);
this->centralWidget()->layout()->addWidget(p_finishButton);
}
break;
default:
break;
}
}
MainWindow::~MainWindow()
{
delete ui;
}
Вот файл определения enum:
//! The system state enum that describes the state that the UI is in
/*!
This is used to keep track of what state that the UI is in. This will
effect how frames are drawn and what variables are initilized or accessed.
Some variables are accessed only when the user is drawing on the canvas,
for example.
*/
enum class systemState
{
ON_START_UP_STATE,/*!< The default value for the enum. This is the state that the program is in when the user first opens the progam in order to load any default settings */
INITIAL_START_UP,/*!< This is the state that the program is in when the user can choose either new or open. The startup screen */
PHYSICS_CHOOSING,/*!< This is the state that the program is in when the user can choose the simulation they would like to run */
MODEL_DEFINING,/*!< This is the state that the program is in when the user is drawing their geometry on the canvas */
SIMULATING,/*!< This is the state that the program is in when the user is simulating their simulation */
VIEWING_RESULTS/*!< This is the state that the program is in when the user is viewing the results of the simulation */
};
Снова я получаю сообщение об ошибке:
QObject :: connect:Невозможно подключиться (null) :: закончено () к MainWindow :: updateGUI ()
, пока у меня есть комментарий QPushButton *p_button;
. Когда закомментировано, ошибка исчезает.Я пытался разместить QPushButton в разных местах кода, но все равно получаю ту же ошибку.
Я весьма озадачен этой ошибкой, потому что я не сталкивался ни с чем подобным!Любая помощь будет принята с благодарностью.
Кстати: я использую последнюю версию QT на момент написания этой статьи.Кроме того, для анимации исчезновения двух кнопок я хотел поместить их в группу QParallelAnimationGroup, но то же самое происходит с группой QParallelAnimationGroup в качестве моего QPushButton!Следовательно, причина закомментирована.Так что удвойте очки, если вы можете предложить решение для обеих проблем!Который я думаю, что проблема с ними та же самая.