Created
January 11, 2014 06:28
独自クラスの作成:Qt
This file contains hidden or 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 hidden or 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment