Unsolved Bootstrap Structure, Is this possible ?
-
http://www.eatoncode.com/resources/shareit/Untitled_Diagram.xml_2016-11-12_10.06.32.png
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->Form1->Hide()
bootstrap->Form2->show();or
bootstrap->Database->function1() from either form1 or form2
Thanks in advance.
-
class BootstrapOrWe { public: void showFirst(); void showSecond(); private: Form1Class Form1; Form2Class Form2; }; inline void BootstrapOrWe::showFirst() { Form2.hide(); Form1.show(); } inline void BootstrapOrWe::showSecond() { Form1.hide(); Form2.show(); }
Note:
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 { Q_OBJECT public: 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())); } signals: 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())); form1.show(); return app.exec(); }
-
Here is my final output.
http://www.eatoncode.com/resources/shareit/Screencast_18-20_14-11-2016.mp4
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...
-
I tried first by including Form1 into Form 2 and Form 2 into Form 1, this worked but did not allow a manageable solution.
-
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.
-
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.
-