PDA

View Full Version : loading *.ui from QByteArray in QFormBuilder



sergey_85
5th November 2009, 20:53
Hi!
I trying load ui form using QFormBuilder from file and it's ok!
But I need to do this from QString (contain *.ui file xml marking)

Is it possible load form from QString? (I'am convert QString to byte array but it's fail!)

Thanks for help!


QFormBuilder builder;
QBuffer buf;
QWidget *wgt = 0;

//QFile file("c:/form.ui");
//file.open(QFile::ReadOnly);

QBuffer buf;
QString content = "ui xml marking here"; //here ui xml content from DB for example

buf.write(content.toUtf8());

QWidget *myWidget = builder.load(&buf, this); // and here error: loading is fail from buffer!
//file.close();
myWidget->show();

QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(myWidget);
setLayout(layout);

Corinzio
5th November 2009, 21:06
Have you tried to use toAscii() on your QString? QBuffer.write() returns the number of byte written maybe you can verify if it writes all the bytes?

sergey_85
5th November 2009, 21:26
Ok i fix it!

buf.setData(content.toAscii().data(),strlen(conten t.toAscii().data()));

Thank!

sergey_85
5th November 2009, 21:27
Ok I fix it!

buf.setData(content.toAscii().data(),strlen(conten t.toAscii().data()));

Thank!