When I use a .ui file in a QT Custom Designer Widget project, crashed and exit, why?
-
wrote on 14 Mar 2025, 01:36 last edited by
ui->setupUi(this);
Here is the code
CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)project(MyCtrl LANGUAGES CXX)
add_library(MyCtrl SHARED myctrl.h myctrl.cpp myctrlplugin.h myctrlplugin.cpp myctrl.ui)
if(NOT DEFINED QT_DESIGNER_PLUGIN_DIR)
set(QT_DESIGNER_PLUGIN_DIR "C:\Qt\6.5.3\mingw_64\plugins\designer")
endif()
message(STATUS "QT_DESIGNER_PLUGIN_DIR: ${QT_DESIGNER_PLUGIN_DIR}")set_target_properties(MyCtrl PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
AUTOMOC ON
AUTOUIC ON
AUTORCC ON
)find_package(Qt6 COMPONENTS Core Gui Widgets Designer REQUIRED)
target_compile_definitions(MyCtrl PRIVATE MYPLUGIN_LIBRARY)
target_link_libraries(MyCtrl PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Designer)Qt Designer plugins dir
set_target_properties(MyCtrl PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${QT_DESIGNER_PLUGIN_DIR}
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${QT_DESIGNER_PLUGIN_DIR}
)
myctrl.h
#ifndef MYCTRL_H
#define MYCTRL_H#include <QWidget>
#include "ui_myctrl.h"
#include "exports.h"namespace Ui
{class MyCtrl;
}
class MYPLUGIN_EXPORT MyCtrl : public QWidget
{
Q_OBJECTpublic:
explicit MyCtrl(QWidget *parent = nullptr);
~MyCtrl();private:
Ui::MyCtrl *ui;
};#endif // MYCTRL_H
myctrl.cpp
#include "myctrl.h"MyCtrl::MyCtrl(QWidget *parent) : QWidget(parent)
{
// ui->setupUi(this);
}MyCtrl::~MyCtrl()
{
delete ui;
} -
wrote on 14 Mar 2025, 01:47 last edited by
If copy the dll file to designer plugin dir, designer.exe can not start.
-
wrote on 14 Mar 2025, 03:09 last edited by
I have found the error:
CoordinateInput::CoordinateInput(QWidget *parent) : QWidget(parent),
ui(new Ui::CoordinateInput)
I lost ",ui(new Ui::CoordinateInput)". -
Great that you found the solution.
Question: How did it happen? Diduic
produce broken C++ code?
Remark: Please use the </> tags to format your code. Makes it so much easier for others to read.
1/4