Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. When I use a .ui file in a QT Custom Designer Widget project, crashed and exit, why?
Forum Updated to NodeBB v4.3 + New Features

When I use a .ui file in a QT Custom Designer Widget project, crashed and exit, why?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 165 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qtaihaozhe
    wrote on 14 Mar 2025, 01:36 last edited by
    #1

    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_OBJECT

    public:
    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;
    }

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qtaihaozhe
      wrote on 14 Mar 2025, 01:47 last edited by
      #2

      If copy the dll file to designer plugin dir, designer.exe can not start.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qtaihaozhe
        wrote on 14 Mar 2025, 03:09 last edited by
        #3

        I have found the error:
        CoordinateInput::CoordinateInput(QWidget *parent) : QWidget(parent),
        ui(new Ui::CoordinateInput)
        I lost ",ui(new Ui::CoordinateInput)".

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Axel Spoerl
          Moderators
          wrote on 15 Mar 2025, 08:42 last edited by Axel Spoerl
          #4

          Great that you found the solution.
          Question: How did it happen? Did uic produce broken C++ code?
          Remark: Please use the </> tags to format your code. Makes it so much easier for others to read.

          Software Engineer
          The Qt Company, Oslo

          1 Reply Last reply
          0

          1/4

          14 Mar 2025, 01:36

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved