View Full Version : how to display window(Window A), when clicked on a button of another window(Window B)
aurora
8th November 2011, 04:24
I hav created two windows, window_A and window_B
I hav button "SHOW" on window_B, when i click on that i want to display window_A.
How can i do that?
I hav files
window_A.h
window_B.h
window_A.cpp
window_B.cpp
main.cpp
where should i write that code?
ChrisW67
8th November 2011, 05:44
With QWidget::show() or QDialog::exec(). You should write that code in the slot that handles clicks on the show button.
aurora
8th November 2011, 05:55
Hi thank u.!
But i'm getting compiler error saying ambiguity in "Show()" function..
I think something wrong with inheritance i made....
I inherited window_A in window_B
prophet0
8th November 2011, 07:24
in window_A.h
include "window_b.h"
private slot:
void showWindow_B();
and pointer to window_b in private so
Window_B *myWindow_B;
in window_A.cpp
add
in your main funtion
connect(ui.startButton, SIGNAL(clicked()), this, SLOT(showWindow_B());
void Window_A::showWindow_B
{
myWindow_B.show();
{
works in my current project with 5 uis :)
aurora
8th November 2011, 18:37
in window_A.h
include "window_b.h"
private slot:
void showWindow_B();
and pointer to window_b in private so
Window_B *myWindow_B;
in window_A.cpp
add
in your main funtion
connect(ui.startButton, SIGNAL(clicked()), this, SLOT(showWindow_B());
void Window_A::showWindow_B
{
myWindow_B.show();
{
works in my current project with 5 uis :)
hi this is what i did....
window_a.h
#ifndef WINDOW_A_H
#define WINDOW_A_H
#include "window_b.h"
#include <QMainWindow>
namespace Ui {
class window_a;
}
class window_a : public QMainWindow
{
Q_OBJECT
public:
explicit window_a(QWidget *parent = 0);
~window_a();
private slots:
void on_pushButton_clicked();
private:
Ui::window_a *ui;
};
#endif // WINDOW_A_H
window_b.h
#ifndef WINDOW_B_H
#define WINDOW_B_H
#include <QMainWindow>
namespace Ui {
class window_b;
}
class window_b : public QMainWindow
{
Q_OBJECT
public:
explicit window_b(QWidget *parent = 0);
~window_b();
private:
Ui::window_b *ui;
};
#endif // WINDOW_B_H
window_a.cpp
#include "window_a.h"
#include "ui_window_a.h"
#include "window_b.h"
window_a::window_a(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::window_a)
{
ui->setupUi(this);
}
window_a::~window_a()
{
delete ui;
}
void window_a::on_pushButton_clicked()
{
window_b * mywindow_b;
mywindow_b->show();
}
window_b.cpp
#include "window_b.h"
#include "ui_window_b.h"
window_b::window_b(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::window_b)
{
ui->setupUi(this);
}
window_b::~window_b()
{
delete ui;
}
main.cpp
#include <QtGui/QApplication>
#include "window_a.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
window_a w;
w.show();
return a.exec();
}
here when i executed the program in qt, window_a displays and when i click on the button(i.e to display window_a), program hangs......nothing comes!!!:(
what is the mistake i made????
aurora
9th November 2011, 03:10
It is addition to previous post.....
when i changed the window_a.cpp as shown below.....One window flashes and disappears..!!!
what is the wrong....please help me to sort it..
Thanks in advance..
window_a.cpp
#include "window_a.h"
#include "ui_window_a.h"
#include "window_b.h"
window_a::window_a(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::window_a)
{
ui->setupUi(this);
}
window_a::~window_a()
{
delete ui;
}
void window_a::on_pushButton_clicked()
{
window_b mywindow_b;
mywindow_b.show();
}
Santosh Reddy
9th November 2011, 04:31
The first method should work if the object is created
Also it is always safe to have a parent to any QObject based object.
void window_a::on_pushButton_clicked()
{
window_b * mywindow_b = new window_b(this);
mywindow_b->show();
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.