Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Showcase
  4. Important for newbie!
Qt 6.11 is out! See what's new in the release blog

Important for newbie!

Scheduled Pinned Locked Moved Showcase
2 Posts 1 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    unixmania
    wrote on last edited by
    #1

    this small app(cross platform) demonstrates two new feature coming by qt5. thats to ability connect functor, non member outer class function and lambda function. main.cpp:
    @
    #include "test.h"

    void outer_func(){std::printf("this is a test by outer class func;)\n");}
    void functor::operator() (bool) {std::printf("this is a test by functor;)\n");}

    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;

    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;)\n");});
    
        Form->setWindowTitle(QString("Form"));
        pushButton->setText(QString("connect functor and outer class func simultaneously"));
    } // setupUi
    

    };
    #endif // TEST_H
    @
    test.pro
    @
    TEMPLATE = app
    TARGET = test
    INCLUDEPATH += .
    QT += widgets
    QMAKE_CXXFLAGS += -std=c++11 #needed for lambda
    HEADERS += test.h
    SOURCES += main.cpp
    @

    1 Reply Last reply
    0
    • U Offline
      U Offline
      unixmania
      wrote on last edited by
      #2

      Also i entered this to wiki. Its title is "new signal slot features qt5"

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved