Results 1 to 6 of 6

Thread: Qt DECLARATIVE_EXAMPLE_MAIN means what?

  1. #1
    Join Date
    Jun 2017
    Posts
    19
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Qt DECLARATIVE_EXAMPLE_MAIN means what?

    I wanted to look at an example C++ code that came with Qt software.
    I looked at main.cpp file at following path:
    Qt Code:
    1. C:\Qt\Examples\Qt-5.9\quick\threading
    To copy to clipboard, switch view to plain text mode 

    This main.cpp has following two lines:
    Qt Code:
    1. #include "../shared/shared.h"
    2. DECLARATIVE_EXAMPLE_MAIN(threading/threading)
    To copy to clipboard, switch view to plain text mode 

    What this DECLARATIVE_EXAMPLE_MAIN means?
    Is there a way to look at this main.cpp's C++ source code and understand features of this main program
    please?
    Thanks

  2. #2
    Join Date
    Jun 2017
    Posts
    19
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Qt DECLARATIVE_EXAMPLE_MAIN means what?

    I found answer to what DECLARATIVE_EXAMPLE_MAIN means?
    This is a macro defined in the following shared.h file.

    Qt Code:
    1. // C:\Qt\Examples\Qt-5.9\quick\shared\shared.h
    2.  
    3. #define DECLARATIVE_EXAMPLE_MAIN(NAME) int main(int argc, char* argv[]) \
    4. {\
    5. QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);\
    6. QGuiApplication app(argc,argv);\
    7. app.setOrganizationName("QtProject");\
    8. app.setOrganizationDomain("qt-project.org");\
    9. app.setApplicationName(QFileInfo(app.applicationFilePath()).baseName());\
    10. QQuickView view;\
    11. if (qgetenv("QT_QUICK_CORE_PROFILE").toInt()) {\
    12. QSurfaceFormat f = view.format();\
    13. f.setProfile(QSurfaceFormat::CoreProfile);\
    14. f.setVersion(4, 4);\
    15. view.setFormat(f);\
    16. }\
    17. view.connect(view.engine(), &QQmlEngine::quit, &app, &QCoreApplication::quit);\
    18. new QQmlFileSelector(view.engine(), &view);\
    19. view.setSource(QUrl("qrc:///" #NAME ".qml")); \
    20. if (view.status() == QQuickView::Error)\
    21. return -1;\
    22. view.setResizeMode(QQuickView::SizeRootObjectToView);\
    23. if (QGuiApplication::platformName() == QLatin1String("qnx") || \
    24. QGuiApplication::platformName() == QLatin1String("eglfs")) {\
    25. view.showFullScreen();\
    26. } else {\
    27. view.show();\
    28. }\
    29. return app.exec();\
    30. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt DECLARATIVE_EXAMPLE_MAIN means what?

    And do you understand what it does?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Jun 2017
    Posts
    19
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Qt DECLARATIVE_EXAMPLE_MAIN means what?

    To understand what it does, I replaced macro with its equivalent C++ program as follows:
    Qt Code:
    1. #include <QDir>
    2. #include <QGuiApplication>
    3. #include <QQmlEngine>
    4. #include <QQmlFileSelector>
    5. #include <QQuickView>
    6.  
    7. int main(int argc, char* argv[])
    8. {
    9. QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    10. QGuiApplication app(argc,argv);
    11. app.setOrganizationName("QtProject");
    12. app.setOrganizationDomain("qt-project.org");
    13. app.setApplicationName(QFileInfo(app.applicationFilePath()).baseName());
    14. QQuickView view;
    15. if (qgetenv("QT_QUICK_CORE_PROFILE").toInt()) {
    16. QSurfaceFormat f = view.format();
    17. f.setProfile(QSurfaceFormat::CoreProfile);
    18. f.setVersion(4, 4);
    19. view.setFormat(f);
    20. }
    21. view.connect(view.engine(), &QQmlEngine::quit, &app, &QCoreApplication::quit);
    22. new QQmlFileSelector(view.engine(), &view);
    23. view.setSource(QUrl("qrc:///threading/threading.qml"));
    24. if (view.status() == QQuickView::Error)
    25. return -1;
    26. view.setResizeMode(QQuickView::SizeRootObjectToView);
    27. if (QGuiApplication::platformName() == QLatin1String("qnx") ||
    28. QGuiApplication::platformName() == QLatin1String("eglfs")) {
    29. view.showFullScreen();
    30. } else {
    31. view.show();
    32. }
    33. return app.exec();
    34. }
    To copy to clipboard, switch view to plain text mode 

    This program gave following output:

    thread_program_output.PNG

    In the next post, I will explain this program and its output.

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt DECLARATIVE_EXAMPLE_MAIN means what?

    Good. The purpose of the macro is to give the developers of QML examples the ability to write a "boilerplate" driver program, where all of the differences between examples are in the QML that the driver loads in the "view.setSource()" line 23. The driver is identical in all examples, what is different is only in the QML.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. #6
    Join Date
    Jun 2017
    Posts
    19
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Qt DECLARATIVE_EXAMPLE_MAIN means what?

    d_stranz,
    Thank you for information about line 23.
    I quickly searched all example programs and found following is list of example programs this boilerplate driver is being used:

    Qt Code:
    1. DECLARATIVE_EXAMPLE_MAIN(qml/xmlhttprequest/xmlhttprequest)
    2. DECLARATIVE_EXAMPLE_MAIN(animation/animation)
    3. DECLARATIVE_EXAMPLE_MAIN(canvas/canvas)
    4. DECLARATIVE_EXAMPLE_MAIN(dialcontrol)
    5. DECLARATIVE_EXAMPLE_MAIN(demos/calqlatr/calqlatr)
    6. DECLARATIVE_EXAMPLE_MAIN(demos/clocks/clocks)
    7. DECLARATIVE_EXAMPLE_MAIN(demos/maroon/maroon)
    8. DECLARATIVE_EXAMPLE_MAIN(demos/rssnews/rssnews)
    9. DECLARATIVE_EXAMPLE_MAIN(demos/samegame/samegame)
    10. DECLARATIVE_EXAMPLE_MAIN(demos/stocqt/stocqt)
    11. DECLARATIVE_EXAMPLE_MAIN(demos/tweetsearch/tweetsearch)
    12. DECLARATIVE_EXAMPLE_MAIN(draganddrop/draganddrop)
    13. DECLARATIVE_EXAMPLE_MAIN(externaldraganddrop/externaldraganddrop)
    14. DECLARATIVE_EXAMPLE_MAIN(imageelements/imageelements)
    15. DECLARATIVE_EXAMPLE_MAIN(keyinteraction/keyinteraction)
    16. DECLARATIVE_EXAMPLE_MAIN(mousearea/mousearea)
    17. DECLARATIVE_EXAMPLE_MAIN(particles/affectors/affectors)
    18. DECLARATIVE_EXAMPLE_MAIN(particles/customparticle/customparticle)
    19. DECLARATIVE_EXAMPLE_MAIN(particles/emitters/emitters)
    20. DECLARATIVE_EXAMPLE_MAIN(particles/imageparticle/imageparticle)
    21. DECLARATIVE_EXAMPLE_MAIN(particles/system/system)
    22. DECLARATIVE_EXAMPLE_MAIN(positioners/positioners)
    23. DECLARATIVE_EXAMPLE_MAIN(accessibility/accessibility)
    24. DECLARATIVE_EXAMPLE_MAIN(righttoleft/righttoleft)
    25. DECLARATIVE_EXAMPLE_MAIN(shadereffects/shadereffects)
    26. DECLARATIVE_EXAMPLE_MAIN(text/text)
    27. DECLARATIVE_EXAMPLE_MAIN(threading/threading)
    28. DECLARATIVE_EXAMPLE_MAIN(touchinteraction/touchinteraction)
    29. DECLARATIVE_EXAMPLE_MAIN(views/views)
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. What is a look of a CMS?
    By HannahDaintree in forum Qt-based Software
    Replies: 1
    Last Post: 7th August 2018, 06:17
  2. what it means
    By JEEVATH in forum Qt Programming
    Replies: 2
    Last Post: 2nd January 2011, 11:18
  3. what`s means this Error Message?
    By blm in forum Qt Programming
    Replies: 2
    Last Post: 15th September 2008, 16:58
  4. signals means protected and what does slots mean
    By babu198649 in forum Qt Programming
    Replies: 1
    Last Post: 27th November 2007, 09:16
  5. QTime private member mds means what?
    By jamadagni in forum Qt Programming
    Replies: 2
    Last Post: 24th March 2006, 18:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.