New Signals and Slots Features in Qt 5: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
AutoSpider (talk | contribs) (Add "cleanup" tag) |
||
Line 1: | Line 1: | ||
{{Cleanup | reason=Auto-imported from ExpressionEngine.}} | |||
This small app (cross platform) demonstrates a few new features come with qt5. thats to ability connect c++ functor objects, non member outer class functions and c+''11 lambda functions. main.cpp: | This small app (cross platform) demonstrates a few new features come with qt5. thats to ability connect c++ functor objects, non member outer class functions and c+''11 lambda functions. main.cpp: | ||
<code> | <code> |
Revision as of 16:11, 3 March 2015
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine. Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean. |
This small app (cross platform) demonstrates a few new features come with qt5. thats to ability connect c++ functor objects, non member outer class functions and c+11 lambda functions. main.cpp:
#include "test.h"
void outer_func(){std::printf("this is a test by outer class func;)");}
void functor::operator() (bool) {std::printf("this is a test by functor;)");}
int main(int argc,char* argv[]){
QApplication app(argc, argv);
Ui_Form ui;
QWidget* form=new QWidget();
ui.setupUi(form);
form->show();
return app.exec();
}
test.h
#ifndef TEST_H
#define TEST_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QWidget>
#include <cstdio>
void outer_func();
class functor{public:void operator() (bool);};
functor a_functor; // create an instance of functor
class Ui_Form{
public:
QPushButton *pushButton;
void setupUi(QWidget *Form){
Form->setObjectName(QStringLiteral("Form"));
Form->resize(600, 100);
pushButton = new QPushButton(Form);
pushButton->setObjectName(QStringLiteral("pushButton"));
pushButton->setGeometry(QRect(10, 50, 580, 33));
pushButton->connect(pushButton,&QAbstractButton::clicked,outer_func);
pushButton->connect(pushButton,&QAbstractButton::clicked,a_functor);
pushButton->connect(pushButton,&QAbstractButton::clicked,[=] (bool){std::printf("This is a test by lambda;)");});
Form->setWindowTitle(QString("Form"));
pushButton->setText(QString("connect functor and outer class func simultaneously"));
} // setupUi
};
#endif // TEST_H
and test.pro
TEMPLATE = app
TARGET = test
INCLUDEPATH= .
QT = widgets # mandatory needed for gui on qt5
QMAKE_CXXFLAGS= -std=c+11 # needed for lambda
HEADERS= test.h
SOURCES += main.cpp