Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



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



  • 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



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



  • ok all the best



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



  • ok carry on



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



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



  • How about dialing?



  • what do you mean with dialing ?



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



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



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





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



  • @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?



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



  • you can use QWorkspace for that



  • 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
    @



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

    QWorkspace is deprecated!

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



  • @cdeepak : i try to rewrite your source, when i run it, it doesn't work...
    i don't know why...



  • @cdeepak:
    i know the problem,
    i write the source using Qt Mobile, but you using Qt Gui,right?
    now, i'm making an application for symbian mobile...



  • @volker : can you help me to solve my problem?
    i'm making an application for symbian mobile using Qt Mobile, not Qt GUI



  • Sorry, I don't have experience with mobile development.

    From a simple point of view, neither QWorkspace nor QMdiArea seem to be appropriate widgets for mobile devices. These are pure desktop widgets, in my opinion.


Log in to reply