Hiding a button on click of another button where both in differnt classes
-
wrote on 7 Jun 2013, 10:00 last edited by
i have pushbutton in forms created in base class mainwidow .now i have created one widget on the same form by drag and drop and again i created a pushbutton on the class widget.now i want that on the click of my pushbutton which was on the widget,my mainwindow button got disappeared…
how can it be possible.?please help me outi have promoted the widget to class mywidget and done some thing like this
.h@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QtGui/QMainWindow>
namespace Ui
{
class MainWindow;
}class MainWindow : public QMainWindow //class mainwindow
{
Q_OBJECTpublic:
MainWindow(QWidget *parent = 0); ~MainWindow();
private:
Ui::MainWindow *ui;private slots:
private slots:
};
class mywidget : public QWidget // class mywidget
{
Q_OBJECTpublic:
mywidget(QWidget *parent = 0);
public slots:
private:
Ui::MainWindow *ui;private slots:
void on_pushButton_2_clicked();
};
#endif // MAINWINDOW_H @.cpp
@
#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);}
MainWindow::~MainWindow()
{
delete ui;
}
mywidget::mywidget(QWidget *parent)
: QWidget(parent){
}
void mywidget::on_pushButton_2_clicked()
{}@
tell me how to do it sir ..
please -
wrote on 7 Jun 2013, 10:18 last edited by
Let your widget emit a signal (you can connect the signal of the button to the signal of the widget) and in your main window you connect it to your slot which removes the button.
-
wrote on 7 Jun 2013, 10:37 last edited by
sir thankyou verymuch for your reply.,but it wil be a honour if you could add the code in my program as i am new to qt.thankyou..
-
wrote on 7 Jun 2013, 13:08 last edited by
Then this is the best way to learn how to use signals and slots.
You will not find anyone in this forum who is doing the work for you. You are more then welcome to ask questions on specific problems you encounter but you have to do the work yourself.
Btw: If this solved you problem, please mark the thread with [SOLVED]
-
wrote on 7 Jun 2013, 13:11 last edited by
sir its not like that.i tried what you suggested me but still i am not able to do it .thats why i was asking you how to implement it in my given codes..
so please help me out in solving this problem...
thankyou -
wrote on 7 Jun 2013, 13:14 last edited by
As I told you: Tell us, what you want to have and what is your problem going there. I (and I am pretty sure no one else as well) will write the code for you but we are happy to help you out with your problems.
-
wrote on 7 Jun 2013, 13:26 last edited by
in the constructor of mainwindow class i wrote
@
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);mywidget wid;
connect(ui->pushButton,SIGNAL(clicked()),wid,SLOT(on_pushButton_2_clicked()));}@
and then ,
@
void MainWindow::on_pushButton_2_clicked()
{
ui->pushButton->hide();}
@basically i want on the click of pushbutton2 ,my pushbutton got disappear.
created pushbutton2 in mywidget class and pushbutton is in mainwindow. -
wrote on 7 Jun 2013, 14:12 last edited by
This code will not even compile. You have to write
@
connect(ui->pushButton,SIGNAL(clicked()),&wid,SLOT(on_pushButton_2_clicked()));
@You can also connect the clicked signal directly to the hide slot.
EDIT: Your on_pushButton_2_clicked() should of course be in your widget and not in the MainWindow
-
wrote on 8 Jun 2013, 04:32 last edited by
thankyou sir,
you was right ,it was not compiling.after changing the code with yours ,it is compiling but still on click of my pushbutton2 nothing is happening .why is that so.
please help me in doing that
5/9