0

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?

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by chikkupa
0

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

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.