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. How to access Qt GUI from an library using qt designer form
Forum Update on Monday, May 27th 2025

How to access Qt GUI from an library using qt designer form

Scheduled Pinned Locked Moved Unsolved General and Desktop
shared libraryqt designer
29 Posts 5 Posters 9.9k Views
  • 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.
  • S Offline
    S Offline
    Srujan
    wrote on 13 Sept 2016, 12:17 last edited by A Former User
    #1

    Hi, I am new to QT. Here I just want to place QT GUI part like dialogs/windows in my library.
    For that I have build my library by creating a new workspace under QT library.
    Now I have created qt designer form that represents dialog part. But not able to access dialog part.
    Here my code

    //
    //dialog.h
    //
    #ifndef DIALOG_H
    #define DIALOG_H
    
    #include <QDialog>
    
    namespace Ui {
    class Dialog;
    }
    
    class Dialog : public QDialog
    {
        Q_OBJECT
    
    public:
        explicit Dialog(QWidget *parent = 0);
        ~Dialog();
    
    private:
        Ui::Dialog *ui;
    };
    
    #endif // DIALOG_H
    
    //
    // dialog.cpp
    //
    #include "dialog.h"
    #include "ui_dialog.h"
    
    Dialog::Dialog(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::Dialog)
    {
        ui->setupUi(this);
    }// Dialog()
    
    Dialog::~Dialog()
    {
        delete ui;
    }
    
    //
    // helper.h
    //
    #ifndef HELPER_H
    #define HELPER_H
    
    #include"dialog.h"
    
    void show_dialog1( );
    
    #endif // HELPER_H
    
    //
    // helper.cpp
    //
    #include"helper.h"
    
    void show_dialog1( )
    {
        Ui:Dialog *uiTestDlg;
        uiTestDlg->show();
    }// show_dialog1()
    

    when I tried to call this show_dialog1(), instead of invoking dialogs its getting crash..
    Any suggestions for proper way of invoking qt gui from shared library..

    Thanks in advance

    J 1 Reply Last reply 13 Sept 2016, 12:44
    0
    • S Srujan
      13 Sept 2016, 12:17

      Hi, I am new to QT. Here I just want to place QT GUI part like dialogs/windows in my library.
      For that I have build my library by creating a new workspace under QT library.
      Now I have created qt designer form that represents dialog part. But not able to access dialog part.
      Here my code

      //
      //dialog.h
      //
      #ifndef DIALOG_H
      #define DIALOG_H
      
      #include <QDialog>
      
      namespace Ui {
      class Dialog;
      }
      
      class Dialog : public QDialog
      {
          Q_OBJECT
      
      public:
          explicit Dialog(QWidget *parent = 0);
          ~Dialog();
      
      private:
          Ui::Dialog *ui;
      };
      
      #endif // DIALOG_H
      
      //
      // dialog.cpp
      //
      #include "dialog.h"
      #include "ui_dialog.h"
      
      Dialog::Dialog(QWidget *parent) :
          QDialog(parent),
          ui(new Ui::Dialog)
      {
          ui->setupUi(this);
      }// Dialog()
      
      Dialog::~Dialog()
      {
          delete ui;
      }
      
      //
      // helper.h
      //
      #ifndef HELPER_H
      #define HELPER_H
      
      #include"dialog.h"
      
      void show_dialog1( );
      
      #endif // HELPER_H
      
      //
      // helper.cpp
      //
      #include"helper.h"
      
      void show_dialog1( )
      {
          Ui:Dialog *uiTestDlg;
          uiTestDlg->show();
      }// show_dialog1()
      

      when I tried to call this show_dialog1(), instead of invoking dialogs its getting crash..
      Any suggestions for proper way of invoking qt gui from shared library..

      Thanks in advance

      J Online
      J Online
      jsulm
      Lifetime Qt Champion
      wrote on 13 Sept 2016, 12:44 last edited by
      #2

      @Srujan said in how to access Qt GUI from an library using qt designer form:

      void show_dialog1( )
      {
      Ui:Dialog *uiTestDlg;
      uiTestDlg->show();
      }

      Well, you are dereferencing a dangling pointer. You did not create any instance of Dialog. It should be:

      void show_dialog1( )
      {
          Ui::Dialog *uiTestDlg = new Ui::Dialog();
          uiTestDlg->show();
      }
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply 13 Sept 2016, 14:55
      3
      • S Offline
        S Offline
        Srujan
        wrote on 13 Sept 2016, 14:27 last edited by Srujan
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • J jsulm
          13 Sept 2016, 12:44

          @Srujan said in how to access Qt GUI from an library using qt designer form:

          void show_dialog1( )
          {
          Ui:Dialog *uiTestDlg;
          uiTestDlg->show();
          }

          Well, you are dereferencing a dangling pointer. You did not create any instance of Dialog. It should be:

          void show_dialog1( )
          {
              Ui::Dialog *uiTestDlg = new Ui::Dialog();
              uiTestDlg->show();
          }
          
          S Offline
          S Offline
          Srujan
          wrote on 13 Sept 2016, 14:55 last edited by
          #4

          @jsulm I agree, but now getting error like-
          invalid use of incomplete type..

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 13 Sept 2016, 14:59 last edited by
            #5

            Hi
            That means it want the include file

            #include "dialog.h"
            in same cpp file where u have
            void show_dialog1( )

            S 1 Reply Last reply 13 Sept 2016, 15:02
            0
            • M mrjj
              13 Sept 2016, 14:59

              Hi
              That means it want the include file

              #include "dialog.h"
              in same cpp file where u have
              void show_dialog1( )

              S Offline
              S Offline
              Srujan
              wrote on 13 Sept 2016, 15:02 last edited by
              #6

              @mrjj already made that update by referring from this link that you have answered earlier..
              https://forum.qt.io/topic/58057/solved-invalid-use-of-incomplete-type-class-ui-mainwindow
              Still getting same error...

              M 1 Reply Last reply 13 Sept 2016, 15:07
              0
              • S Srujan
                13 Sept 2016, 15:02

                @mrjj already made that update by referring from this link that you have answered earlier..
                https://forum.qt.io/topic/58057/solved-invalid-use-of-incomplete-type-class-ui-mainwindow
                Still getting same error...

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 13 Sept 2016, 15:07 last edited by
                #7

                @Srujan
                ok. then something is really wrong :)

                Just to be 1000% sure. it still say same error if u do :

                void show_dialog1( )
                {
                Dialog *uiTestDlg = new Dialog();
                uiTestDlg->show();
                }

                and then
                Build->clean all
                Build->qmake
                Build->Rebuild all.

                S 1 Reply Last reply 13 Sept 2016, 15:13
                0
                • M mrjj
                  13 Sept 2016, 15:07

                  @Srujan
                  ok. then something is really wrong :)

                  Just to be 1000% sure. it still say same error if u do :

                  void show_dialog1( )
                  {
                  Dialog *uiTestDlg = new Dialog();
                  uiTestDlg->show();
                  }

                  and then
                  Build->clean all
                  Build->qmake
                  Build->Rebuild all.

                  S Offline
                  S Offline
                  Srujan
                  wrote on 13 Sept 2016, 15:13 last edited by
                  #8

                  @mrjj
                  Able to build, but when trying to access from app its again getting crash..
                  And in console its showing error like "QWidget: Must construct a QApplication before a QWidget"

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 13 Sept 2016, 15:18 last edited by
                    #9

                    "QWidget: Must construct a QApplication before a QWidget"

                    That often comes from Global variables. Like in main.cpp

                    And as much as i wish, i cannot guess the reason for crash :)

                    Please show main.cpp.

                    S 1 Reply Last reply 13 Sept 2016, 15:26
                    0
                    • M mrjj
                      13 Sept 2016, 15:18

                      "QWidget: Must construct a QApplication before a QWidget"

                      That often comes from Global variables. Like in main.cpp

                      And as much as i wish, i cannot guess the reason for crash :)

                      Please show main.cpp.

                      S Offline
                      S Offline
                      Srujan
                      wrote on 13 Sept 2016, 15:26 last edited by
                      #10

                      @mrjj
                      Actually in our case we are using some standard applications like cryptokimanager e.t.c..

                      M 1 Reply Last reply 13 Sept 2016, 15:29
                      0
                      • S Srujan
                        13 Sept 2016, 15:26

                        @mrjj
                        Actually in our case we are using some standard applications like cryptokimanager e.t.c..

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 13 Sept 2016, 15:29 last edited by
                        #11

                        @Srujan said in how to access Qt GUI from an library using qt designer form:

                        @mrjj
                        Actually in our case we are using some standard applications like cryptokimanager e.t.c..

                        Meaning that there should not be any globals variables?
                        Try google
                        "QWidget: Must construct a QApplication before a QWidget"
                        and you see there are various reason for this message.

                        Most often the use of "extern" or static variables.

                        S 1 Reply Last reply 13 Sept 2016, 17:57
                        0
                        • M mrjj
                          13 Sept 2016, 15:29

                          @Srujan said in how to access Qt GUI from an library using qt designer form:

                          @mrjj
                          Actually in our case we are using some standard applications like cryptokimanager e.t.c..

                          Meaning that there should not be any globals variables?
                          Try google
                          "QWidget: Must construct a QApplication before a QWidget"
                          and you see there are various reason for this message.

                          Most often the use of "extern" or static variables.

                          S Offline
                          S Offline
                          Srujan
                          wrote on 13 Sept 2016, 17:57 last edited by
                          #12

                          @mrjj
                          Through normal application I am able to invoke QT GUI part.
                          Here my application code..

                          //
                          //main.cpp
                          //
                          #include <QCoreApplication>
                          #include"helper.h"
                          #include <QtWidgets/QApplication>
                          
                          int main(int argc, char *argv[])
                          {
                              QApplication a(argc, argv); // previously its like QCoreApplication
                          
                              show_dialog1( );
                          
                              return a.exec();
                          }
                          
                          //changes in .pro file
                          QT       += gui
                          
                          greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                          

                          After these changes in application project, able to invoke GUI part in shared library

                          But through our standard applications not able to invoke.

                          Any idea-
                          That what changes required for such applications....!!

                          Any way thanks for your support....

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 13 Sept 2016, 19:14 last edited by
                            #13

                            Hi,

                            What are your "standard application" ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            S 1 Reply Last reply 14 Sept 2016, 05:27
                            2
                            • SGaistS SGaist
                              13 Sept 2016, 19:14

                              Hi,

                              What are your "standard application" ?

                              S Offline
                              S Offline
                              Srujan
                              wrote on 14 Sept 2016, 05:27 last edited by
                              #14

                              @SGaist
                              Its "cryptokimanager"

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 14 Sept 2016, 07:49 last edited by
                                #15

                                Let me rephrase that: what toolkit does it use ?

                                Is it already using Qt ?

                                Are you building that app yourself or are you writing a plugin for it and have no access to its internals ?

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                S 1 Reply Last reply 14 Sept 2016, 10:24
                                0
                                • SGaistS SGaist
                                  14 Sept 2016, 07:49

                                  Let me rephrase that: what toolkit does it use ?

                                  Is it already using Qt ?

                                  Are you building that app yourself or are you writing a plugin for it and have no access to its internals ?

                                  S Offline
                                  S Offline
                                  Srujan
                                  wrote on 14 Sept 2016, 10:24 last edited by Srujan
                                  #16

                                  @SGaist
                                  Its a tool for managing and validating a pkcs#11 module..
                                  For more info please refer Cryptoki manager

                                  1 Reply Last reply
                                  0
                                  • VRoninV Offline
                                    VRoninV Offline
                                    VRonin
                                    wrote on 14 Sept 2016, 10:40 last edited by
                                    #17

                                    Can you post your code from which you call show_dialog1( ); ?

                                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                    ~Napoleon Bonaparte

                                    On a crusade to banish setIndexWidget() from the holy land of Qt

                                    S 1 Reply Last reply 14 Sept 2016, 11:28
                                    1
                                    • VRoninV VRonin
                                      14 Sept 2016, 10:40

                                      Can you post your code from which you call show_dialog1( ); ?

                                      S Offline
                                      S Offline
                                      Srujan
                                      wrote on 14 Sept 2016, 11:28 last edited by
                                      #18

                                      @VRonin
                                      simply I have called 'show_dialog1();' from one of exported functions in shared library..

                                      1 Reply Last reply
                                      0
                                      • VRoninV Offline
                                        VRoninV Offline
                                        VRonin
                                        wrote on 14 Sept 2016, 11:33 last edited by VRonin
                                        #19

                                        I suspect you are not creating the application. try Q_ASSERT(QCoreApplication::instance()); if it asserts (i.e. instance() returns NULL) then it means you simply forgot to crate the QApplication before creating any QWidget

                                        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                        ~Napoleon Bonaparte

                                        On a crusade to banish setIndexWidget() from the holy land of Qt

                                        1 Reply Last reply
                                        0
                                        • SGaistS Offline
                                          SGaistS Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on 14 Sept 2016, 12:54 last edited by
                                          #20

                                          The question you are not answering is: are you working on that software code source directly ?

                                          Interested in AI ? www.idiap.ch
                                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          S 1 Reply Last reply 19 Sept 2016, 10:46
                                          1

                                          5/29

                                          13 Sept 2016, 14:59

                                          topic:navigator.unread, 24
                                          • Login

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