Ive been trying to code a GUI application in qt but im having trouble trying to get a button work.

homewindow.h:

#ifndef HOMEWINDOW_H
#define HOMEWINDOW_H

#include <QWidget>

class homeWindow :  public QWidget
{
    Q_OBJECT

public:
    homeWindow();
    ~homeWindow();
    void init();

private slots:
    int when();

private:
    QWidget *aWidget;


};

#endif // HOMEWINDOW_H

homewindow.cpp:

#include "homewindow.h"
#include "loginwindow.h"

#include <QtGui>
#include <qapplication.h>
#include <QDesktopWidget>
#include <QVBoxLayout>
#include <QObject>
#include <iostream>

using namespace std;

homeWindow::homeWindow()
{
}

homeWindow::~homeWindow()
{
}

void homeWindow::init()
{
    aWidget = new QWidget; // create a new QWidget

    QPushButton *button1 = new QPushButton("Log Out", this); // log out button

    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(button1);

    connect(button1,SIGNAL(clicked()),this,SLOT(when())); // dosent work

    aWidget->setLayout(layout);

    aWidget->setGeometry(QRect (20,20,300,700)); // size of window

    QRect qRect(QApplication::desktop()->screenGeometry());
    int iXpos=qRect.width()/2-aWidget->width()/2;
    int iYpos=qRect.height()/2-aWidget->height()/2;
    aWidget->move(iXpos,iYpos);
    aWidget->show();

}

int homeWindow::when()
{
    // dosent get here !
    cout<<"here";
    return 0;
}

i just dont know why its not working?

make the connection statement at the end of the function and try once more.

It is better to use constructor than 'init()'.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.