0

I'm doing the Udemy C++ Qt tutorial. The idea is to have a QPushButton button in a window.

When I run this, I get an empty window. Using Qt 5.5 in Win7.

Here are my files:

main.cpp

#include<QApplication>
#include"S_S.h"

int main(int argc, char *argv[])
{
    QApplication app(argc,argv);
    S_S MyTest;
    MyTest.show();
    return app.exec();
}

S_S.h

#ifndef S_S_H
#define S_S_H
#include<QApplication>
#include<QWidget>
#include<QPushButton>

class S_S : public QWidget
{
public:
    S_S();
private:
    QPushButton *Button1;

};

#endif // S_S_H

S_S.cpp

#include"s_s.h"

S_S::S_S():QWidget()
{
    Button1=new QPushButton;
    Button1->setText("Cancel");
    connect(Button1,SIGNAL(clicked()),qApp,SLOT(quit()));

}

1 Answers1

2

You probably want to construct the QPushButton and pass in a parent widget:

Button1 = new QPushButton(this);

I assume you want the S_S instance to be the parent.

You might also want to set the size and location of the button:

Button1->setGeometry(QRect(QPoint(100, 100), QSize(200, 50)));

There is an example here of using QPushButton.

Sam
  • 3,320
  • 1
  • 17
  • 22
  • Okay, like I said it's a tutorial. I'm more interested in why it doesn't work. Or rather, which part of the tutorial code is deprecated and/or outdated. – astroannie Jan 23 '16 at 03:53
  • Do you have a link to the tutorial or the tutorial's code? Is the code you put in your question exactly what is in the tutorial? – Sam Jan 23 '16 at 09:57