c++ - Qt Creator 没有名为 stackedWidget 的成员

标签 c++ qt qt-creator qt5.2

我刚刚在 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/

相关文章:

c++ - C++ STL 中的正则表达式

c++ - C++转换参数初始化问题

c++ - 静态库链接失败

c++ - Qt + VS2010 : The program can't start because <xyz>. 你的电脑缺少dll

qt - 如何使 Qt Creator 以与 Qt 库中的函数相同的方式显示我的函数的弹出式文档?

Qt Creator 不显示 QML 文件夹

c++ - 六角射线转换

.net - 是否可以使用 Silverlight 制作真正的跨平台应用程序?

c++ - 无法在 qt-creator 中调试,cdb 崩溃 0xC0000135

c++ - 查找范围 [a, b] 中不在给定 std::set S 中的所有数字