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?

Recommended Answers

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

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

Jump to Post

All 2 Replies

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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.