Hello
I design a simple Qt designer custom plugin, i need this plugin for Qt Designer, its ok and it has no problem, i start to design my main program, i want to load a ui file which contains my custom widgets, i use uitools to load this ui file and also with no problem,
but i need to access this custom widgets in ui file after loading, here is a small problem and it's just not work. i attached my custom plugin source and two test projects, what can i do ? any suggestion ? PLEASE!?!
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
main.cpp===========
#include <QApplication>
#include <QUiLoader>
#include <QWidget>
#include <QFile>
#include <QMainWindow>
#include <QtGui>
#include "QGLabel.h"//???????????????????
//Qt 4.7.0
int main(int argc, char **argv)
{
Q_INIT_RESOURCE(test);
QFile uiFile
(":/test.ui");
QWidget *ui
= loader.
load(&uiFile
);
uiFile.close();
ui->show();
//-------------------------------------------------------------------------
//after loading this form i need to access its child widgets
// QGLabel *l1 = qFindChild<QGLabel *>(ui, "g0");
qDebug() << "---------------------";
// qDebug() << l1;//here shoes the pointer is null
qDebug() << "---------------------";
//but when i try to access one of this child custom widgets
//my program crashed
// l1->setText("i can change it");//here crashed
//so i need to make a QList of this custom widgets
//QList<QGLabel *> allQGLabels = ui->findChildren<QGLabel *>();
//PLEASE what can i do??
return app.exec();
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
main.cpp===========
#include <QApplication>
#include <QUiLoader>
#include <QWidget>
#include <QFile>
#include <QMainWindow>
#include <QtGui>
#include "QGLabel.h"//???????????????????
//Qt 4.7.0
int main(int argc, char **argv)
{
Q_INIT_RESOURCE(test);
QApplication app(argc, argv);
QUiLoader loader;
QFile uiFile(":/test.ui");
uiFile.open(QIODevice::ReadOnly);
QWidget *ui = loader.load(&uiFile);
uiFile.close();
ui->show();
//-------------------------------------------------------------------------
//after loading this form i need to access its child widgets
// QGLabel *l1 = qFindChild<QGLabel *>(ui, "g0");
qDebug() << "---------------------";
// qDebug() << l1;//here shoes the pointer is null
qDebug() << "---------------------";
//but when i try to access one of this child custom widgets
//my program crashed
// l1->setText("i can change it");//here crashed
//so i need to make a QList of this custom widgets
//QList<QGLabel *> allQGLabels = ui->findChildren<QGLabel *>();
//PLEASE what can i do??
return app.exec();
}
To copy to clipboard, switch view to plain text mode
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++
test.prj ===========
CONFIG += uitools
RESOURCES += test.qrc
SOURCES += main.cpp
#HEADERS += QGLabel.h
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++
Bookmarks