是否有可能让Qt Creators UI设计师为它无法识别的类创建插槽?
Is it possible to get Qt Creators Ui designer to create slots for a class that it doesn't recognize?
也就是说,通过右键单击小部件并选择"转到插槽..."来创建插槽。
示例 1,这有效:
#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;
};
#endif // MAINWINDOW_H
这不会,因为显然设计器会寻找 Ui::MainWindow*,如果找不到它,就会完全吓坏了(得到"找不到包含 'Ui::MainWindow' 的类......")
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <memory>
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
std::unique_ptr<Ui::MainWindow> ui;
};
#endif // MAINWINDOW_H
我基本上是在寻找一种方法来告诉Qt"是的,我真的是那个类。我知道它不包含 Ui::MainWindow*,没关系,一切都会好起来的......"。除非我错了,并且由于某种原因,类实际上需要将其作为普通指针。
"找不到包含'Ui::MainWindow'的类..."当 QT 创建者找不到您的"主窗口.cpp"文件来放置插槽函数定义时,会发生问题。
确保您的 mainwindow.h 具有以下内容作为私有变量:
Ui::MainWindow *ui;
以下包含位于您的主窗口中.cpp文件中:
#include "ui_mainwindow.h"
如果这不起作用,则您的 QT 创建者可能存在错误。尝试更新您的软件。
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 使用std::multimap迭代器创建std::list
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 使用CMake创建QML插件
- 如何在c++中为模板函数实例创建快捷方式
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 提升 ASIO 无法识别计时器对象
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 从udp接收帧对于人脸识别来说太慢
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 试图在visual studio上用C++创建一个桌面应用程序
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 如何在C++20中创建模板别名的推导指南
- 如何为模板化对象创建模板向量?VS正在投掷C3203
- 如何创建一个空的全局类并在启动时实例化它
- C++ 无法识别创建进程'telnet'
- 是否有可能让Qt Creators UI设计师为它无法识别的类创建插槽?
- 临时对象 - 何时创建它们,如何在代码中识别它们
- C++ typedef 和返回类型:如何让编译器识别使用 typedef 创建的返回类型
- Microsoft Visual Studio 2010将不会编译、加载/创建文件,也不会识别iostream