This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mainwindow.h" | |
#include "ui_mainwindow.h" | |
#include <QDebug> | |
MainWindow::MainWindow(QWidget *parent) : | |
QMainWindow(parent), | |
ui(new Ui::MainWindow) | |
{ | |
ui->setupUi(this); | |
MyClass *mycladd = new MyClass(); | |
mycladd->setName("yamada"); | |
mycladd->setAge("20"); | |
qDebug() << mycladd->name; | |
qDebug() << mycladd->age; | |
} | |
MainWindow::~MainWindow() | |
{ | |
delete ui; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MAINWINDOW_H | |
#define MAINWINDOW_H | |
#include <QMainWindow> | |
#include <QString> | |
namespace Ui { | |
class MainWindow; | |
} | |
class MainWindow : public QMainWindow | |
{ | |
Q_OBJECT | |
public: | |
explicit MainWindow(QWidget *parent = 0); | |
~MainWindow(); | |
private: | |
Ui::MainWindow *ui; | |
}; | |
class MyClass | |
{ | |
private: | |
public: | |
QString name; | |
QString age; | |
MyClass() | |
{ | |
//デフォルトコンストラクタ | |
} | |
void setName(QString strName) | |
{ | |
name = strName; | |
} | |
void setAge(QString strAge){ | |
age = strAge; | |
} | |
}; | |
#endif // MAINWINDOW_H | |
ウイザードを使って、自動でクラスフィルとヘッダーファイルを作成する。
C++ Class を選択する。
クラス名を入力する。
確認する。
プロジェクトに新しいクラスとヘッダーファイルが作成されている。
0 件のコメント:
コメントを投稿