Qt Creator没有名为stackedWidget的成员 [英] Qt Creator no member named stackedWidget
问题描述
我刚刚在QT-Creator中设计了自己的ui,由于主应用程序基于两个面板,所以我决定使用StackedWidget来更改布局",而无需打开新窗口.
I've just designed my ui in the QT-Creator and, as the main application is based on two panels, I decided to use the StackedWidget for "change the layout" without opening a new window.
因此,我添加了一个名为:stackedWidget(默认)的QTStackedWidget.
So, I added a QTStackedWidget named: stackedWidget (as default).
问题出在mainwindow.cpp中,我添加了一个包含以下内容的自定义SLOT:
The problem is in mainwindow.cpp, I added a custom SLOT that contain:
ui->stackedWidget->setCurrentIndex(1);
在构建此文件时,编译器会说:
when I build this the compiler says:
mainwindow.cpp:25:错误:'Ui :: MainWindow'中没有名为'stackedWidget'的成员
ui-> stackedWidget-> setCurrentIndex(1);
~~ ^
mainwindow.cpp:25: error: no member named 'stackedWidget' in 'Ui::MainWindow'
ui->stackedWidget->setCurrentIndex(1);
~~ ^
在qt-creator本身中,我也无法将信号附加到stackedWidget,因为它没有向我显示setCurrentIndex SLOT ...
also in the qt-creator itself I was unable to attach a signal to the stackedWidget because it doesn't show to me the setCurrentIndex SLOT...
有什么建议吗?
请注意,我是C ++的新手,几年前我刚刚在PyQt4中使用Qt.
Please note that I'm a noob with C++ I just used Qt a couple of years ago with PyQt4.
mainwindow.h:
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
private slots:
void showOtherPage();
void showMainPage();
};
#endif // MAINWINDOW_H
mainiwindow.cpp:
mainiwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qDebug() << "MainWindow - Debug Mode ON";
connect(ui->btnOther, SIGNAL(clicked()), SLOT(showOtherPage()));
}
void MainWindow::showOtherPage()
{
qDebug() << "Showing Other Page";
ui->stackedWidget->setCurrentIndex(1);
}
void MainWindow::showMainPage()
{
qDebug() << "Showing Main Page";
ui->stackedWidget->setCurrentIndex(0);
}
MainWindow::~MainWindow()
{
delete ui;
}
推荐答案
我有一个非常相似的问题.UI动作之一被定义为其他动作并被使用.我有一个 ui,没有对此成员的名为xyz
的编译错误,没有可能的解释.
I had a very similar issue.
One of the UI actions was defined as the others and used.
I had a ui has no member named xyz
compilation error for this one only, without possible explanation.
我可以通过取消/选中项目编译选项中的 Shadow build
选项来解决该问题!
I could solve it by unchecking/checking the Shadow build
option in the project compilation options!
希望这样可以节省别人30分钟,我只是失去了:)
Hope it saves someone the 30 minutes I just lost :)
这篇关于Qt Creator没有名为stackedWidget的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!