Qt静的メンバー関数の呼び出し非静的メンバー変数、非静的メンバー関数
#ifndef MYSTAIC_H
#define MYSTAIC_H
#include
#include
#include
#include
class MyStaic : public QObject
{
Q_OBJECT
public:
explicit MyStaic(QObject *parent = 0);
~MyStaic();
static void test();
static void test(MyStaic &myStaic);
static QMutex* mutex;
void notStaticfun();
private:
int tmp ;
};
#endif // MYSTAIC_H
#include "mystaic.h"
QMutex* MyStaic::mutex = new QMutex;
MyStaic::MyStaic(QObject *parent) : QObject(parent)
{
qDebug() << "This is ";
tmp = 10;
}
MyStaic::~MyStaic()
{
qDebug() << "this is ";
}
void MyStaic::test()
{
qDebug() << "OK";
mutex->lock();
mutex->unlock();
}
void MyStaic::test(MyStaic &myStaic)
{
qDebug() << "This is not static Member variables tmp =" << myStaic.tmp ;
myStaic.notStaticfun();
}
void MyStaic::notStaticfun()
{
qDebug() << "This is not static fun";
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "mystaic.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
MyStaic::test();
MyStaic* myNoStatic = new MyStaic(this);
MyStaic::test(*myNoStatic);
}
MainWindow::~MainWindow()
{
delete ui;
}
#include "mainwindow.h"
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
このプログラムの実行結果は次のとおりです.
OK
This isコンストラクタ
This is not static Member variables tmp = 10
This is not static fun
this is析出