[SOLVED] how to link a form(.ui) to another form using push button
-
wrote on 14 Feb 2012, 03:42 last edited by
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... -
wrote on 14 Feb 2012, 04:18 last edited by
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_OBJECTpublic:
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
-
wrote on 14 Feb 2012, 04:22 last edited by
thanks for reply,
i will try now.... -
wrote on 14 Feb 2012, 04:30 last edited by
ok all the best
-
wrote on 14 Feb 2012, 04:35 last edited by
thanks a lot...
it really help me so much... -
wrote on 14 Feb 2012, 05:04 last edited by
ok carry on
-
wrote on 14 Feb 2012, 05:45 last edited by
@cdeepak : can i ask again?
how about child have child?
i use the same way but is not correct..
thanks -
wrote on 14 Feb 2012, 07:04 last edited by
i try again, and correct...
hehe,
thanks -
wrote on 14 Feb 2012, 09:24 last edited by
How about dialing?
-
wrote on 14 Feb 2012, 18:53 last edited by
what do you mean with dialing ?
-
wrote on 15 Feb 2012, 04:22 last edited by
i mean, when use a push button we can send short message service....
can you help me? -
wrote on 15 Feb 2012, 04:29 last edited by
maybe you can give me an example about how to send sms using Qt...
thanks luisvaldes88 -
wrote on 15 Feb 2012, 05:17 last edited by
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.
-
wrote on 15 Feb 2012, 06:00 last edited by
okey, thanks all...
i will learn it... -
wrote on 16 Feb 2012, 03:25 last edited by
@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? -
wrote on 16 Feb 2012, 05:31 last edited by
Hi,
i am searching the sample mdi parent chid project in my pc wait for while -
wrote on 16 Feb 2012, 05:45 last edited by
you can use QWorkspace for that
-
wrote on 16 Feb 2012, 05:56 last edited by
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_OBJECTpublic:
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
@ -
wrote on 16 Feb 2012, 11:26 last edited by
[quote author="cdeepak" date="1329371126"]you can use QWorkspace for that
[/quote]QWorkspace is deprecated!
Please use [[Doc:QMdiArea]] and [[Doc:QMdiSubWindow]].
1/24