在Visual Studio中将自定义代码添加到Qt UIC生成的文件中
Adding custom code to Qt UIC generated file in Visual Studio
我使用的是带有Qt插件的Microsoft Visual Studio。为了设计我的UI,我使用Qt Designer工具直接获取.UI文件,Qt UIC从该文件生成.h文件。
现在Qt设计器有一些缺点,因此我现在想添加我的自定义代码,以便进一步完善UI。可以将其直接添加到Qt UIC生成的.h文件中,但每次重新编译时,更改都会丢失。
我应该如何将自己的代码添加到Qt UIC生成的.h文件中?
正如您所观察到的,编辑生成的.h文件是个坏主意,该文件在重新编译时会被覆盖。添加抛光代码的一个地方是在组成生成的UI对象的类的构造函数中。例如:
// MainWindow.cpp
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
// Additional polish
ui.textEdit->setText("Hello !");
}
// MainWindow.h
#include "ui_MainWindow.h" // the generated UI header
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
private:
Ui::MainWindowClass ui;
};
相关文章:
- Qt VTK交互风格的信号到小部件
- QT在错误的班级中寻找空位
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 如何在Qt窗口小部件中使用QStringView(或QStringRef)
- 如何在Qt C++中更改光标
- 如何在MS Visual Studio 2019中运行QT UI
- QT通过C++添加映射QML项目
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 使用Qt C++计算类似Git的SHA1哈希
- Qt focusObjectChanged example?
- 如何在cpp文件之间切换窗口?在Qt中
- Qt和C++:将QLineEdit添加到QTabWidget中
- Qt 创建者编译错误"找不到 UIC.exe从 msvc 2012 路径"
- Qt:使用uic生成ui_classes,按类名动态加载
- 在Visual Studio中将自定义代码添加到Qt UIC生成的文件中
- QT UIC不会自动添加自定义小部件的头
- 在Qt (c++)上使用UIC
- Qt Creator语言 - uic 不会在构建时自动运行