why isnt my button showing?
Hi,
Im trying to create a A GUI.
In my main, im trying to create the "QUIT" button, but it wont show when i run it. I would appreaciate if anyone would tell me why it wont show.
Here is my code:
Quote:
#include <QApplication>
#include <QPushButton>
#include <QWidget>
#include "browseimages.h"
class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0);
};
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
QPushButton *b_quit = new QPushButton(tr("Quit"), this);
connect(b_quit, SIGNAL(clicked()), qApp, SLOT(b_quit()));
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
BrowseImages window;
window.show();
return app.exec();
}
Thank you.
Re: why isnt my button showing?
Where are you creating/showing an instance of MyWidget?
Also b_quit will not look good. You could add it to a layout to handle its position and size.
Re: why isnt my button showing?
Thanks Marcel,
I forgot to creat an instance of MyWidget. I fixed that, and i also used layout to handle the position and size of my quit button.
But, my "quit" button (b_quit) isnt working. The window wont close when i press "Quit". I would like to know where is the problem.
Here is the fixed code:
Code:
#include <QApplication>
#include "browseimages.h"
#include <QPushButton>
#include <QWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <Qlabel>
{
public:
};
MyWidget
::MyWidget(QWidget *parent
) {
connect(b_quit, SIGNAL(clicked()), qApp, SLOT(b_quit()));
b_search->setFixedHeight(40);
b_quit->setFixedHeight(40);
v_search->setAlignment(Qt::AlignCenter);
l_search_img
->setPixmap
(QPixmap("images/manual.png"));
v_search->addWidget(l_search_img);
v_search->addWidget(b_search);
h_quit->addStretch();
h_quit->addWidget(b_quit);
h_quit->addStretch();
layout_mid->addLayout(v_search);
layout_vert->addLayout(layout_mid);
layout_vert->addSpacing(30);
layout_vert->addLayout(h_search);
layout_vert->addLayout(h_quit);
layout_vert->addSpacing(30);
this->setLayout(layout_vert);
}
int main(int argc, char **argv)
{
MyWidget widget;
widget.show();
return app.exec();
}
Thanks in advance,
Re: why isnt my button showing?
Your connect is wrong. Should be:
Code:
connect(b_quit, SIGNAL(clicked()), qApp, SLOT(quit()));
Re: why isnt my button showing?
Quote:
Originally Posted by
marcel
Your connect is wrong. Should be:
Code:
connect(b_quit, SIGNAL(clicked()), qApp, SLOT(quit()));
Thank you what a silly mistake :o