Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Bootstrap Structure, Is this possible ?
Forum Updated to NodeBB v4.3 + New Features

Bootstrap Structure, Is this possible ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 999 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • EatonCodeE Offline
    EatonCodeE Offline
    EatonCode
    wrote on last edited by EatonCode
    #1

    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.

    kshegunovK 1 Reply Last reply
    0
    • EatonCodeE EatonCode

      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.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @EatonCode

      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.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      2
      • S Offline
        S Offline
        Shahazan Ali
        wrote on last edited by VRonin
        #3
        #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();
        }
        
        1 Reply Last reply
        0
        • EatonCodeE Offline
          EatonCodeE Offline
          EatonCode
          wrote on last edited by EatonCode
          #4

          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...

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved