I guess this might be what you wanted. Seems to work fine for me...
#include <QApplication>
#include <QUiLoader>
#include <QFile>
#include <QLabel>
#include <QLayout>
#include <QGridLayout>
int main(int argc, char **argv){
file.
open(QFile::ReadOnly);
QWidget *widget
= loader.
load(&file,
0);
if(!widget) return 2;
QWidget *l
= widget
->findChild<QWidget
*>
("centralwidget");
if(!l){
qDebug("widget not found");
delete widget;
return 2;
}
if(!lay){ qDebug("widget has no layout"); return 2; }
if(!grid){ qDebug("Not a grid"); return 2; }
grid
->addWidget
(new QLabel("TESTING"),
0,
0,
1,
4);
widget->show();
int r = app.exec();
delete widget;
return r;
}
#include <QApplication>
#include <QUiLoader>
#include <QFile>
#include <QLabel>
#include <QLayout>
#include <QGridLayout>
int main(int argc, char **argv){
QApplication app(argc, argv);
QUiLoader loader;
QFile file("temp.ui");
file.open(QFile::ReadOnly);
QWidget *widget = loader.load(&file, 0);
if(!widget) return 2;
QWidget *l = widget->findChild<QWidget*>("centralwidget");
if(!l){
qDebug("widget not found");
delete widget;
return 2;
}
QLayout *lay = l->layout();
if(!lay){ qDebug("widget has no layout"); return 2; }
QGridLayout *grid = qobject_cast<QGridLayout*>(lay);
if(!grid){ qDebug("Not a grid"); return 2; }
grid->addWidget(new QLabel("TESTING"), 0, 0, 1, 4);
widget->show();
int r = app.exec();
delete widget;
return r;
}
To copy to clipboard, switch view to plain text mode
Bookmarks