How to access Qt GUI from an library using qt designer form
-
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
-
@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(); }
-
Hi
That means it want the include file#include "dialog.h"
in same cpp file where u have
void show_dialog1( ) -
@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. -
"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.
-
@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.
-
@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....
-
Hi,
What are your "standard application" ?
-
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 ?
-
The question you are not answering is: are you working on that software code source directly ?