我刚刚在 QT-Creator 中设计了我的用户界面,由于主要应用程序基于两个面板,我决定使用 StackedWidget 来“更改布局”而不打开新窗口。
因此,我添加了一个 QTStackedWidget,名称为:stackedWidget(默认)。
问题出在 mainwindow.cpp 中,我添加了一个包含以下内容的自定义 SLOT:
ui->stackedWidget->setCurrentIndex(1);
当我构建这个时,编译器说:
mainwindow.cpp:25: error: no member named 'stackedWidget' in 'Ui::MainWindow'
ui->stackedWidget->setCurrentIndex(1);
~~ ^
同样在 qt-creator 本身中,我无法将信号附加到 stackedWidget,因为它没有向我显示 setCurrentIndex SLOT...
有什么建议吗?
请注意,我是 C++ 的新手,几年前我刚刚将 Qt 与 PyQt4 结合使用。
主窗口.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
主窗口.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 has no member named xyz
编译错误,仅此一个,没有可能的解释。
我可以通过取消选中/选中项目编译选项中的 Shadow build
选项来解决它!
希望它可以节省我刚刚失去的 30 分钟 :)
关于c++ - Qt Creator 没有名为 stackedWidget 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24549660/