[Qt-interest] why is this not allowed?

Ross Bencina rossb-lists at audiomulch.com
Sat May 8 08:11:23 CEST 2010


>QGridLayout signupLayout = *loginLayout;
>
>I'd like to reuse exacly the same, but add an extra field.

What you are asking for is a deep copy of a tree of widgets/layouts. I don't 
know a quick way to do that (perhaps Qt has a function?). QWidget doesn't 
define polymorphic clone functionality so it's a tall order. If you really 
want to do it that way, you could implement it yourself by traversing the 
parent-child tree and cloning individual widgets using the metaobject 
protocol (in other words: a lot of work.)

I think a beter Qt-style approach would be:

Have a createLoginLayout() function which constructs the login layout, then 
you can call that function and modify the result to create the signup 
layout:

QGridLayout *createLoginLayout() { /* create the layout and add the widgets 
*/ }

QGridLayout *createSignupLayout() {
    QGridLayout *result = createLoginLayout();
    /* add signup specific stuff */
    return result;
}

Or perhaps createLoginLayout() returns something designed in Designer.

HTH

Ross. 




More information about the Qt-interest-old mailing list