Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [SOLVED] how to link a form(.ui) to another form using push button

[SOLVED] how to link a form(.ui) to another form using push button

Scheduled Pinned Locked Moved Qt Creator and other tools
24 Posts 3 Posters 20.3k Views
  • 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.
  • Y Offline
    Y Offline
    yola-yoli
    wrote on 14 Feb 2012, 03:42 last edited by
    #1

    Hey all,
    I am new at Qt creator.
    I have a problem, how to link a form(.ui) to another form using push button?
    Can you give some example for me?
    Because I still don't understand even after reading the tutorial...
    Thank you...

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on 14 Feb 2012, 04:18 last edited by
      #2

      Hi,
      mainwindow.h
      @#ifndef MAINWINDOW_H
      #define MAINWINDOW_H

      #include <QMainWindow>
      #include "mainwindow1.h" //adding second window
      namespace Ui {
      class MainWindow;
      }

      class MainWindow : public QMainWindow
      {
      Q_OBJECT

      public:
      explicit MainWindow(QWidget *parent = 0);
      MainWindow1 *objmain1; // creating object for the second window
      ~MainWindow();
      private slots:
      void btnaction(); // creating slots
      private:
      Ui::MainWindow *ui;
      };

      #endif // MAINWINDOW_H@

      mainwindow.cpp

      @#include "mainwindow.h"
      #include "ui_mainwindow.h"

      MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
      {
      ui->setupUi(this);
      connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(btnaction())); // creating connections
      }

      void MainWindow::btnaction()
      {
      objmain1 = new MainWindow1;
      objmain1->show(); //opening second form
      }
      MainWindow::~MainWindow()
      {
      delete ui;
      }
      @

      this will open the new window seperately. if you want to open the new window inside the first window means you have go for the parent child concept

      1 Reply Last reply
      1
      • Y Offline
        Y Offline
        yola-yoli
        wrote on 14 Feb 2012, 04:22 last edited by
        #3

        thanks for reply,
        i will try now....

        1 Reply Last reply
        0
        • ? This user is from outside of this forum
          ? This user is from outside of this forum
          Guest
          wrote on 14 Feb 2012, 04:30 last edited by
          #4

          ok all the best

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            yola-yoli
            wrote on 14 Feb 2012, 04:35 last edited by
            #5

            thanks a lot...
            it really help me so much...

            1 Reply Last reply
            0
            • ? This user is from outside of this forum
              ? This user is from outside of this forum
              Guest
              wrote on 14 Feb 2012, 05:04 last edited by
              #6

              ok carry on

              1 Reply Last reply
              0
              • Y Offline
                Y Offline
                yola-yoli
                wrote on 14 Feb 2012, 05:45 last edited by
                #7

                @cdeepak : can i ask again?
                how about child have child?
                i use the same way but is not correct..
                thanks

                1 Reply Last reply
                0
                • Y Offline
                  Y Offline
                  yola-yoli
                  wrote on 14 Feb 2012, 07:04 last edited by
                  #8

                  i try again, and correct...
                  hehe,
                  thanks

                  1 Reply Last reply
                  0
                  • Y Offline
                    Y Offline
                    yola-yoli
                    wrote on 14 Feb 2012, 09:24 last edited by
                    #9

                    How about dialing?

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      luisvaldes88
                      wrote on 14 Feb 2012, 18:53 last edited by
                      #10

                      what do you mean with dialing ?

                      Muchos quieren, pocos pueden, algunos consiguen.

                      1 Reply Last reply
                      0
                      • Y Offline
                        Y Offline
                        yola-yoli
                        wrote on 15 Feb 2012, 04:22 last edited by
                        #11

                        i mean, when use a push button we can send short message service....
                        can you help me?

                        1 Reply Last reply
                        0
                        • Y Offline
                          Y Offline
                          yola-yoli
                          wrote on 15 Feb 2012, 04:29 last edited by
                          #12

                          maybe you can give me an example about how to send sms using Qt...
                          thanks luisvaldes88

                          1 Reply Last reply
                          0
                          • ? This user is from outside of this forum
                            ? This user is from outside of this forum
                            Guest
                            wrote on 15 Feb 2012, 05:17 last edited by
                            #13

                            i think this will help for u Try this link "http://www.developer.nokia.com/Community/Wiki/CS001616_-_Send_SMS_using_Qt_Mobility". and let me know what happens.

                            1 Reply Last reply
                            0
                            • ? This user is from outside of this forum
                              ? This user is from outside of this forum
                              Guest
                              wrote on 15 Feb 2012, 05:37 last edited by
                              #14

                              Try this

                              http://www.qtcentre.org/archive/index.php/t-8380.html

                              http://www.developer.nokia.com/Community/Wiki/Creating_database_driven_applications_using_Qt

                              1 Reply Last reply
                              0
                              • Y Offline
                                Y Offline
                                yola-yoli
                                wrote on 15 Feb 2012, 06:00 last edited by
                                #15

                                okey, thanks all...
                                i will learn it...

                                1 Reply Last reply
                                0
                                • Y Offline
                                  Y Offline
                                  yola-yoli
                                  wrote on 16 Feb 2012, 03:25 last edited by
                                  #16

                                  @cdeepak : i want ask about parent child concept...
                                  i have two form,
                                  form 1 is main menu and form 2 is sub menu...
                                  i want create a button in form 2, the button used to back in form1,
                                  i use the ame way but failed...
                                  can you help me?

                                  1 Reply Last reply
                                  0
                                  • ? This user is from outside of this forum
                                    ? This user is from outside of this forum
                                    Guest
                                    wrote on 16 Feb 2012, 05:31 last edited by
                                    #17

                                    Hi,
                                    i am searching the sample mdi parent chid project in my pc wait for while

                                    1 Reply Last reply
                                    0
                                    • ? This user is from outside of this forum
                                      ? This user is from outside of this forum
                                      Guest
                                      wrote on 16 Feb 2012, 05:45 last edited by
                                      #18

                                      you can use QWorkspace for that

                                      1 Reply Last reply
                                      0
                                      • ? This user is from outside of this forum
                                        ? This user is from outside of this forum
                                        Guest
                                        wrote on 16 Feb 2012, 05:56 last edited by
                                        #19

                                        Hi,
                                        here i have used menubar instead of QPushbutton so u try to understand the concept and do it in your own way.....
                                        mdiwindow.cpp

                                        @#include "mdiwindow.h"
                                        #include "ui_mdiwindow.h"
                                        #include <QMessageBox>
                                        #include <QVariant>
                                        #include <QString>
                                        MDIWindow::MDIWindow(QWidget *parent) :
                                        QMainWindow(parent),
                                        ui(new Ui::MDIWindow)
                                        { ui->setupUi(this);
                                        workspace = new QWorkspace;
                                        setCentralWidget(workspace);

                                        connect(ui->actionChild1,SIGNAL(triggered()),this,SLOT(OpenChild1()));
                                        connect(ui->actionChild2,SIGNAL(triggered()),this,SLOT(OpenChild2()));
                                        //connect(&cw1,SIGNAL(ChildWindow1Closed()),this,SLOT(StatusUpdate()));
                                        

                                        connect(ui->actionChild_window_status,SIGNAL(triggered()),SLOT(ChildStatus()));
                                        connect(ui->actionActivated_Window,SIGNAL(triggered()),SLOT(FindActivatedWindow()));
                                        connect(ui->actionChild_Window_Count,SIGNAL(triggered()),SLOT(FindChildCount()));

                                        }

                                        MDIWindow::~MDIWindow()
                                        {
                                        delete ui;
                                        }
                                        void MDIWindow::FindChildCount()
                                        {
                                        //Type Conversion from int to string
                                        int a =workspace->windowList().count();
                                        QString str;
                                        str=QVariant(a).toString();
                                        str=QString::number(a,16);
                                        statusBar()->showMessage("Child Window Count is" + str );
                                        }
                                        void MDIWindow::StatusUpdate()
                                        {

                                        }
                                        void MDIWindow::FindActivatedWindow()
                                        {
                                        if(!workspace->windowList().isEmpty())
                                        statusBar()->showMessage(workspace->activeWindow()->windowTitle() + " is Activated Now " );
                                        else
                                        statusBar()->showMessage("No Active Child Window");
                                        }
                                        void MDIWindow::ChildStatus()
                                        {
                                        if(workspace->windowList().isEmpty())
                                        {
                                        statusBar()->showMessage(" No Child Window Opened");
                                        }
                                        else
                                        {
                                        statusBar()->showMessage("Child Window Opened");
                                        }
                                        }
                                        void MDIWindow::OpenChild1()
                                        {
                                        if(!ObjChild1->isVisible())
                                        {
                                        ObjChild1 = new ChildWindow1;
                                        }
                                        workspace->addWindow(ObjChild1);
                                        ObjChild1->setWindowTitle("Child1");
                                        ObjChild1->show();
                                        statusBar()->showMessage(workspace->activeWindow()->windowTitle() + " Opened Just Now");
                                        }
                                        void MDIWindow::OpenChild2()
                                        {
                                        if(!ObjChild2->isVisible())
                                        {
                                        ObjChild2 = new ChildWindow2;
                                        }
                                        workspace->addWindow(ObjChild2);
                                        ObjChild2->setWindowTitle("Child2");
                                        ObjChild2->show();
                                        //statusBar()->showMessage("Child Window opened");
                                        statusBar()->showMessage(workspace->activeWindow()->windowTitle() + " Opened Just Now");
                                        }
                                        @

                                        mdiwindow.h

                                        @#ifndef MDIWINDOW_H
                                        #define MDIWINDOW_H

                                        #include <QMainWindow>
                                        #include "childwindow1.h"
                                        #include "childwindow2.h"
                                        #include <QWorkspace>

                                        namespace Ui {
                                        class MDIWindow;
                                        }

                                        class MDIWindow : public QMainWindow
                                        {
                                        Q_OBJECT

                                        public:
                                        explicit MDIWindow(QWidget *parent = 0);
                                        ~MDIWindow();

                                        //ChildWindow1 cw1;
                                        private slots:
                                        void OpenChild1();
                                        void OpenChild2();
                                        void ChildStatus();
                                        void FindActivatedWindow();
                                        void FindChildCount();
                                        public slots:
                                        void StatusUpdate();

                                        private:
                                        Ui::MDIWindow ui;
                                        QWorkspace workspace;
                                        ChildWindow1
                                        ObjChild1;
                                        ChildWindow2
                                        ObjChild2;
                                        };

                                        #endif // MDIWINDOW_H
                                        @

                                        1 Reply Last reply
                                        0
                                        • G Offline
                                          G Offline
                                          goetz
                                          wrote on 16 Feb 2012, 11:26 last edited by
                                          #20

                                          [quote author="cdeepak" date="1329371126"]you can use QWorkspace for that
                                          [/quote]

                                          QWorkspace is deprecated!

                                          Please use [[Doc:QMdiArea]] and [[Doc:QMdiSubWindow]].

                                          http://www.catb.org/~esr/faqs/smart-questions.html

                                          1 Reply Last reply
                                          0

                                          1/24

                                          14 Feb 2012, 03:42

                                          • Login

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