QtCreator redundant for GUI development?



  • Hello,

    I am new to Qt and have been teaching myself from the tutorials and examples on this site and from the book C++ GUI Programming with Qt 4 by Blanchette and Summerfield.

    I notice that both mainly code the GUIs as opposed to developing the GUI part using QtDesigner/QtCreator.

    I felt that I should be able to save myself a lot of code writing by having a go at one of the tutorials but developing all of the GUI using Qt Creator and just filling in the functions in code.

    However I find that as soon as I try to build the project I get errors saying things like 'nameLineEdit was not declared in this scope" and the only way to get rid of the errors seems to be to write in all the code that I was trying to avoid writing in the first place! At the moment QtCreator seems a bit redundant - am I missing something?

    For example I am having a go at this tutorial: http://doc.qt.nokia.com/4.7/tutorials-addressbook-part2.html

    I made my GUI using QtCreator and then tried adding in the addContact function:

    @void AddressBook::addContact()
    {
    oldName = nameLineEdit->text();
    oldAddress = addressTextEdit->toPlainText();

     nameLineEdit->clear();
     addressTextEdit->clear();
    
     nameLineEdit->setReadOnly(false);
     nameLineEdit->setFocus(Qt::OtherFocusReason);
     addressTextEdit->setReadOnly(false);
    
     addPushButton->setEnabled(false);
     submitPushButton->show();
     cancelPushButton->show();
    

    }
    @

    When I build it complains that it doesn't recognise any of the widgets - I would of expected that as I drop them onto the form it would edit the code so that it does recognise them?

    Should I just be doing everything in code and forgetting about QtCreator?

    Sorry for the long winded first post! Any guidance would be much appreciated!

    Jimbo



  • Am i missing something? But as i see that tutorial doesn't use UI file (designer).

    So if you added a UI file you will have a class which contain an ui member pointer or object (you need to initialize that member) and then access the Widgets (you added in Designer) something like:
    @
    ui->NameOfWidget; //if ui is pointer
    //or
    ui.NameOfWidget; //if ui is object
    @
    You can read "this":http://doc.qt.nokia.com/4.7/designer-using-a-ui-file.html page to see the ways ui file can be integrated with C++ code.



  • Aha! That's it!

    Nope you weren't missing something - I was! :)

    It makes more sense now. I'll have a read of the page you mention too.

    Out of interest do many Qt developers use QtCreator or do they go for just the code approach? Most things I see online are all coded.

    Thanks Zlatomir



  • Qt Creator is an IDE. You can write your C++ code, compile it and you can use it to graphically design the forms. You probably mean Qt Designer, which is the stand alone GUI designer. Qt Creator has an embedded Designer version.

    There is no general rule on how to design the forms. Test both (manual and graphical) and take that one that you feel more comfortable with.

    I personally use both approaches simultaneously (and so do many others, too). I prefer the Designer for the more complicated forms (eg. many widgtes, sophisticated layout, etc.) and take the manual way only for small/simple forms. You can achieve practically everything with either approach (in fact the designer forms are translated to some C++ code that gets included to your project).



  • In both cases (Ui Designer file or coded by you in C++) the interface end-up as C++ code, you can have a look in some ui_UIFILENAME.h (the generated code).

    So i say you get comfortable with both methods and then choose the one you like the most ;) you will get a "hunch" when you should use one method or another.



  • Thanks for your help guys!

    I will keep on exploring both methods


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.