Bootstrap Structure, Is this possible ?


    What I want to do is have a button that will hide FORM1 and Open FORM2, then another button on FORM2 that will hide FORM2 and Show Form1 again.

    I also want to separate the database functions using a .pro file but to reuse the instance. I wish to call the same reuseable custom functions in the sqlite database.

    I can do this very easily in C# but I am struggling with Qt and C++.

    I was thinking I could do something like this.



    bootstrap->Database->function1() from either form1 or form2

    Thanks in advance.

  • Moderators


    class BootstrapOrWe
        void showFirst();
        void showSecond();
        Form1Class Form1;
        Form2Class Form2;
    inline void BootstrapOrWe::showFirst()
    inline void BootstrapOrWe::showSecond()

    It's rather poor habit to mix capital and lower leading letters for variable names (and or classes). You should adopt a consistent style and stick to it. For example - classes (and/or types) will start will capital letter while variables will start with a lower letter, and words will be camelcased (how Qt does it).

    Kind regards.

  • #include <QPushButton>
    #include <QApplication>
    class Form : public QWidget {
        Form(QWidget* p = 0) : QWidget(p)
        QPushButton * btn = new QPushButton("Hide Me and Show Other one", this);
     connect(btn, SIGNAL(clicked(bool)), this, SIGNAL(hideMeAndShowOtherOne()));
    void hideMeAndShowOtherOne();
    int main(int argc, char *argv[])
    QApplication app(argc, argv);
    Form form1, form2;
    QObject::connect(&form1, SIGNAL(hideMeAndShowOtherOne()), &form2, SLOT(show()));
    QObject::connect(&form2, SIGNAL(hideMeAndShowOtherOne()), &form1, SLOT(show()));;
    return app.exec();

  • Here is my final output.

    Thanks for your help. I am still learning, and this is more trial and error for me.. If you see where I can improve let me know.

    I tried 3 ways...

    1. I tried first by including Form1 into Form 2 and Form 2 into Form 1, this worked but did not allow a manageable solution.

    2. I tried to use signal and slots to manage and call the other forms which worked well but I am new to Signal and Slots and it seemed like a lot of work to emit signals and catch slots for every little small action I wanted to take. This was probably the best way but it really seemed confusing if I added to many actions.

    3. I just included the bootstrap class in Form1 and Form2 and referenced the bootstrap class header file. This third option seems more manageable and it's very easy to add more forms or objects such as a database.

    If you have a suggestion please let me know.

Log in to reply