Combine forms and classes dynamically



  • Hi,

    I am new to qt and so far it seems great. I am also new to c++ but I do have some programming experience with perl. I thought it would be a good thing to create the forms I need and then combine them into the main module. I have a main form which has a tool bar and the main window is a tab control and would like to dynamically add a tab called "invoice 123456" to the containing tabcontrol. I built the invoice form to have a class attached so that I can use functions that would only be available to invoices. So how do I include the entire invoice class and all into a dynamically created tab?



  • You want a custom class for designer?
    Perhaps the comments in here will help you:
    http://developer.qt.nokia.com/forums/viewthread/345



  • I am not sure about that forum.

    I am thinking I am not describing what I am after properly. I have in my project 2 forms the mainwindow and invoice. When I added invoice to my project in creator, I got it to build a class at that time. Not sure if it was a good idea.

    I want the invoice form incorporated into a tab in the mainwindow form. Dynamically if possible? I want to be able to do this so that I can add Information to the tab text.



  • blenkhn, you may make Form class with QtCreator class form wizard (As I understand, you need QWidget subclass).
    After, you should include header of your invoice form class to mainwindow and
    will create object of your invoice widget.
    And after you should add you invoice object to mainwindow layout.



  • bq. So how do I include the entire invoice class and all into a dynamically created tab?bq.

    Your invoice form is a widget (QWidget descendant)
    You create your invoice form widget and add it to a new tab.

    @InvoiceWidget *myNewInvoiceWidget = new InvoiceWidget(...);
    myTabWidget->addTab(myNewInvoiceWidget, QString("Invoice #%1").arg(++invoiceNum));@



  • Thanks for the reply infoctopus, I don't like to sound like a total newbie but the (...) is the name of the .h file or the ui file? In this case InvoiceToolBox.h and InvoiceToolBox.ui, does this method also embed the class, Invoicetoolbox.cpp? If I wanted to see this on startup how would I include it in the main.cpp?

    @#include <QtGui/QApplication>
    #include "mainwindow.h"
    #include "invoicetoolbox.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    InvoiceToolBox i;
    w.show();
    InvoiceWidget *myNewInvoiceWidget = new InvoiceWidget(InvoiceToolBox.h);
    myTabWidget->addTab(myNewInvoiceWidget, QString("Invoice #%1").arg(++invoiceNum));

    return a.exec&#40;&#41;;
    

    }
    @



  • blenkhn, don't afraid to sound like a newbie, be afraid to miss important things :)
    Generally I think that now is a good time to read some book on C++ basics.

    InvoiceWidget is a QWidget. You can see its constructor in Assistant.



  • There is a good documentation in "Using a Designer UI File in Your Application":http://doc.qt.nokia.com/latest/designer-using-a-ui-file.html on how to make your Designer created UI work with your code.

    Basically you should:

    • Create your UI with Designer
    • choose one of the three methods mentioned in the docs (see the link)
    • Then you can call new InvoiceWidget(this) and put that in your code.

    Despite that, a good C++ introduction would be of help, as infoctopus wrote.



  • a good C++ introduction is of extreme need, not just help
    blenkhn, don't treat that as a mentoring, it's a real need for you. You'd like it all :)



  • Hey Guys thanks for the help, I am looking at some books online to buy. I am not new to programming and thought my background in perl would help, but there are language differences. modules instead of classes and the methodology seems to be a little different.

    Do you have any suggestions as to a good book or online tutorial? I have been reading learncpp.com but I thought I could skip a couple of lessons as they seemed to be mostly basic lessons - guess I shouldn't be trying to skip ahead.

    I have both ui's built and I have read the page Volker linked to and I would like to use the qtuitools as I feel a need to have multiple invoices open so that I could go back to an invoice and add information to it as needed. Right now I was wanting to see if I could get the second ui to load into a tab page on the first ui. After that should be fairly simple to get it into a tab with a button click. Can you guys help with an example?





  • As for C++ +Qt book, I'd recommend "An Introduction to Design Patterns in C plus plus with Qt 4" by Alan Ezust and Paul Ezust

    it's even free: http://cartan.cas.suffolk.edu/oopdocbook/html/



  • [quote author="blenkhn" date="1291675356"]Hey Guys thanks for the help, I am looking at some books online to buy. I am not new to programming and thought my background in perl would help, but there are language differences. modules instead of classes and the methodology seems to be a little different.[/quote]

    Perl is not really helpful in that case, I must admit. I came from that background too. Things are quite different. You need to get comfortable with header files/includes, compilation units and how all these things fit together.

    [quote author="blenkhn" date="1291675356"]I have both ui's built and I have read the page Volker linked to and I would like to use the qtuitools as I feel a need to have multiple invoices open so that I could go back to an invoice and add information to it as needed. Right now I was wanting to see if I could get the second ui to load into a tab page on the first ui. After that should be fairly simple to get it into a tab with a button click. Can you guys help with an example?[/quote]

    I can only recommend, that you start from scratch. You should make yourself comfortable with the principles of programming in C++, the basic Qt concepts (widgets, form files created with designer, combining them together), then how to add widgets using C++, and so forth. Don't make too big steps in the beginning, it will not work and is frustrating.



  • [quote author="infoctopus" date="1291676411"]As for C++ +Qt book, I'd recommend "An Introduction to Design Patterns in C plus plus with Qt 4" by Alan Ezust and Paul Ezust

    it's even free: http://cartan.cas.suffolk.edu/oopdocbook/html/[/quote]

    Please make sure to add this reference to the books wiki.


Log in to reply
 

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