/-------main.cpp------/
#include <QApplication>
#include "mywidget.h"
int main(int argc, char *argv[]){
QApplication a(argc, argv);
MyWidget *w = new MyWidget;
w->show();
return a.exec();
}
/---------mywidget.h--------/
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QLabel>
#include <QVBoxLayout>
#include <QWidget>
class MyWidget : public QWidget{
Q_OBJECT
public:
explicit MyWidget(QWidget *parent = 0);
signals:
public slots:
private :
QLabel *l; QVBoxLayout *layout;};
#endif // MYWIDGET_H
/----------mywidget.cpp-------/
#include "mywidget.h"
#include <QLabel>
MyWidget::MyWidget(QWidget *parent) : QWidget(parent){
l = new QLabel();
l->setText("Hello");
layout->addWidget(l);
this->setLayout(layout);
this->setFixedSize(375, 100);
this->setWindowTitle("Hello world!");
}
小白求教
#include <QApplication>
#include "mywidget.h"
int main(int argc, char *argv[]){
QApplication a(argc, argv);
MyWidget *w = new MyWidget;
w->show();
return a.exec();
}
/---------mywidget.h--------/
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QLabel>
#include <QVBoxLayout>
#include <QWidget>
class MyWidget : public QWidget{
Q_OBJECT
public:
explicit MyWidget(QWidget *parent = 0);
signals:
public slots:
private :
QLabel *l; QVBoxLayout *layout;};
#endif // MYWIDGET_H
/----------mywidget.cpp-------/
#include "mywidget.h"
#include <QLabel>
MyWidget::MyWidget(QWidget *parent) : QWidget(parent){
l = new QLabel();
l->setText("Hello");
layout->addWidget(l);
this->setLayout(layout);
this->setFixedSize(375, 100);
this->setWindowTitle("Hello world!");
}
小白求教