Quoted
#ifndef BOX_H
#define BOX_H
#include <qmainwindow.h>
#include <qpushbutton.h>
class QPushButton;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
private:
QPushButton *button;
};
#endif
Quoted
#include <QtGui>
#include "box.h"
MainWindow::MainWindow()
{
button = new QPushButton("Hello");
}
Quoted
#include "box.h"
#include <QtGui>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
MainWindow *Wind = new MainWindow;
Wind->show();
return app.exec();
}
|
|
Source code |
1 2 3 4 5 |
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
// create a pushbutton and pass the pointer to its parent widget.
button = new QPushButton("This is a button",this);
}
|
Quoted
MainWindow(QWidget *parent=0);
Quoted
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
This post has been edited 1 times, last edit by "eleanor" (Sep 14th 2006, 6:23pm)
Quoted
Originally posted by eleanor
Hey.
I did this:
Quoted
MainWindow(QWidget *parent=0);
And I did this:
Quoted
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
Here I declared a constructor MainWindow to use a pointer to a type QWidget (that gets the value of a parent) ----> and then it passes that value to a QMainWindow constructor. Is that right?
Quoted
Can I only ask you: which value does it get? --> can you tell me in example?
This post has been edited 1 times, last edit by "moogle" (Sep 14th 2006, 6:28pm)
Quoted
#ifndef BOX_H
#define BOX_H
#include <qmainwindow.h>
#include <qpushbutton.h>
class QPushButton;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent=0);
private:
QPushButton *button;
};
class MainWindow2 : public MainWindow
{
Q_OBJECT
public:
MainWindow2(MainWindow *parent2=0);
private:
QPushButton *button2;
};
#endif
Quoted
#include <QtGui>
#include "box.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
button = new QPushButton("Hello",this);
}
MainWindow2::MainWindow2(MainWindow *parent2) : MainWindow(parent2)
{
button2 = new QPushButton("Kako_si?",this);
}
Quoted
#include "box.h"
#include <QtGui>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
MainWindow *Wind = new MainWindow;
Wind->show();
return app.exec();
}
This post has been edited 1 times, last edit by "eleanor" (Sep 15th 2006, 12:54am)