Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Use dialogs in Qt 6
Forum Updated to NodeBB v4.3 + New Features

Use dialogs in Qt 6

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
14 Posts 3 Posters 2.4k Views 3 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.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #2

    Did you create a QApplication instead of QGuiApplication in your main.cpp?

    (Z(:^

    Q 1 Reply Last reply
    1
    • sierdzioS sierdzio

      Did you create a QApplication instead of QGuiApplication in your main.cpp?

      Q Offline
      Q Offline
      qcoderpro
      wrote on last edited by qcoderpro
      #3

      @sierdzio

      Yes, I used it and the project ran, but the output is very odd! Here're my files:

      main.cpp:

      #include <QApplication>
      #include <QQmlApplicationEngine>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          const QUrl url(u"qrc:/QML_3/main.qml"_qs);
          QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                           &app, [url](QObject *obj, const QUrl &objUrl) {
              if (!obj && url == objUrl)
                  QCoreApplication::exit(-1);
          }, Qt::QueuedConnection);
          engine.load(url);
      
          return app.exec();
      }
      

      CMakeLists.txt:

      cmake_minimum_required(VERSION 3.16)
      
      project(QML_3 VERSION 0.1 LANGUAGES CXX)
      
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
      
      find_package(Qt6 6.2 COMPONENTS Quick REQUIRED)
      find_package(Qt6 COMPONENTS Widgets REQUIRED)
      
      qt_add_executable(appQML_3
          main.cpp
      )
      
      qt_add_qml_module(appQML_3
          URI QML_3
          VERSION 1.0
          QML_FILES main.qml 
      )
      
      set_target_properties(appQML_3 PROPERTIES
          MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
          MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
          MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
          MACOSX_BUNDLE TRUE
          WIN32_EXECUTABLE TRUE
      )
      
      target_compile_definitions(appQML_3
          PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
      target_link_libraries(appQML_3
          PRIVATE Qt6::Quick)
      target_link_libraries(appQML_3 PRIVATE Qt6::Widgets)
      

      And this is the output! :|

      sd.PNG

      Why is it this way, please!?
      The element MessageDialog is still not recognized! :(

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #4

        It's not recognised by Qt Creator but it does work. I can see the window and the dialog in this screenshot. Qt Creator's QML code model will often fail to recognise stuff, don't worry about it. As long as it works at runtime, all is good.

        I see the dialog lacks text which you've set, though. That might be a problem. Do you see any warnings or errors in the console output?

        (Z(:^

        Q 1 Reply Last reply
        1
        • sierdzioS sierdzio

          It's not recognised by Qt Creator but it does work. I can see the window and the dialog in this screenshot. Qt Creator's QML code model will often fail to recognise stuff, don't worry about it. As long as it works at runtime, all is good.

          I see the dialog lacks text which you've set, though. That might be a problem. Do you see any warnings or errors in the console output?

          Q Offline
          Q Offline
          qcoderpro
          wrote on last edited by
          #5

          @sierdzio

          No, almost everything looks fine! I just get these in the Output Window:
          00:47:51: Running steps for project QML_3...
          00:47:51: Starting: "C:\Qt\Tools\CMake_64\bin\cmake.exe" --build D:/Projects/QML/QML_3/build-QML_3-Desktop_Qt_6_2_3_MinGW_64_bit-Debug --target all
          [1/10 7.0/sec] Automatic MOC for target appQML_3
          [2/9 9.6/sec] Running AUTOMOC file extraction for target appQML_3
          [3/4 1.1/sec] Building CXX object CMakeFiles/appQML_3.dir/main.cpp.obj
          [4/4 1.3/sec] Linking CXX executable appQML_3.exe
          00:47:55: The process "C:\Qt\Tools\CMake_64\bin\cmake.exe" exited normally.
          00:47:55: Elapsed time: 00:03.

          So what should be the reason for the window to appear this way to you, please?
          That's really strange we have to do that much modification, and suffer from the output and the red line under the element just to be able to use it in the code! :|

          Q 1 Reply Last reply
          0
          • Q qcoderpro

            @sierdzio

            No, almost everything looks fine! I just get these in the Output Window:
            00:47:51: Running steps for project QML_3...
            00:47:51: Starting: "C:\Qt\Tools\CMake_64\bin\cmake.exe" --build D:/Projects/QML/QML_3/build-QML_3-Desktop_Qt_6_2_3_MinGW_64_bit-Debug --target all
            [1/10 7.0/sec] Automatic MOC for target appQML_3
            [2/9 9.6/sec] Running AUTOMOC file extraction for target appQML_3
            [3/4 1.1/sec] Building CXX object CMakeFiles/appQML_3.dir/main.cpp.obj
            [4/4 1.3/sec] Linking CXX executable appQML_3.exe
            00:47:55: The process "C:\Qt\Tools\CMake_64\bin\cmake.exe" exited normally.
            00:47:55: Elapsed time: 00:03.

            So what should be the reason for the window to appear this way to you, please?
            That's really strange we have to do that much modification, and suffer from the output and the red line under the element just to be able to use it in the code! :|

            Q Offline
            Q Offline
            qcoderpro
            wrote on last edited by
            #6

            @qcoderpro

            Or don't we have a better alternative, please?

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #7

              Sorry I don't understand anymore what the problem is.

              So at runtime the program works OK, no problems, right?

              You are only complaining about the editor telling you about MessageDialog being not recognised? That's just Qt Creator's code model being stupid. You can just ignore it, it's pretty common.

              (Z(:^

              Q 1 Reply Last reply
              0
              • sierdzioS sierdzio

                Sorry I don't understand anymore what the problem is.

                So at runtime the program works OK, no problems, right?

                You are only complaining about the editor telling you about MessageDialog being not recognised? That's just Qt Creator's code model being stupid. You can just ignore it, it's pretty common.

                Q Offline
                Q Offline
                qcoderpro
                wrote on last edited by
                #8

                @sierdzio
                That red underline would be ignorable, that is.
                But the problem is the way the MessageDialog looks, that's undoubtedly not what we want. It's shown at the screenshot sent above if you, please, scroll up a little.

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #9

                  OK, I misunderstood your previous comment then.

                  I've never used this MessageDialog thing so it's hard for me to say. The code looks ok, maybe take a look at command line output (not compilation output you pasted above but Application Output tab in Qt Creator). Maybe there are some warnings there?

                  The documentation suggests this dialog is NOT available on Windows:

                  A native platform message dialog is currently available on the following platforms:
                  iOS
                  Android
                  WinRT

                  (https://doc.qt.io/qt-5/qml-qt-labs-platform-messagedialog.html)

                  maybe that's the reason. Try the MessageDialog from QtQuick.Dialogs instead of Qt.labs. https://doc.qt.io/qt-5/qml-qtquick-dialogs-messagedialog.html

                  (Z(:^

                  Q 1 Reply Last reply
                  1
                  • sierdzioS sierdzio

                    OK, I misunderstood your previous comment then.

                    I've never used this MessageDialog thing so it's hard for me to say. The code looks ok, maybe take a look at command line output (not compilation output you pasted above but Application Output tab in Qt Creator). Maybe there are some warnings there?

                    The documentation suggests this dialog is NOT available on Windows:

                    A native platform message dialog is currently available on the following platforms:
                    iOS
                    Android
                    WinRT

                    (https://doc.qt.io/qt-5/qml-qt-labs-platform-messagedialog.html)

                    maybe that's the reason. Try the MessageDialog from QtQuick.Dialogs instead of Qt.labs. https://doc.qt.io/qt-5/qml-qtquick-dialogs-messagedialog.html

                    Q Offline
                    Q Offline
                    qcoderpro
                    wrote on last edited by
                    #10

                    Application Output tab in Qt Creator). Maybe there are some warnings there?

                    No, nothing different. Normal.

                    maybe that's the reason

                    Yes, that must be.

                    Try the MessageDialog from QtQuick.Dialogs instead of Qt

                    I created a new QtQuick project using CMake and Qt version 5.15 and tested an example of that page but get this error!
                    QQmlApplicationEngine failed to load component
                    qrc:/main.qml:3:1: module "QtQuick.Dialogs" version 1.3 is not installed

                    JKSHJ 1 Reply Last reply
                    0
                    • sierdzioS Offline
                      sierdzioS Offline
                      sierdzio
                      Moderators
                      wrote on last edited by
                      #11

                      I don't know, maybe try some lower import like 1.2 or 1.1.

                      (Z(:^

                      Q 1 Reply Last reply
                      0
                      • sierdzioS sierdzio

                        I don't know, maybe try some lower import like 1.2 or 1.1.

                        Q Offline
                        Q Offline
                        qcoderpro
                        wrote on last edited by
                        #12

                        @sierdzio

                        I don't know, maybe try some lower import like 1.2 or 1.1.

                        I've already tried both (and even one without a version) but similar errors! :(

                        1 Reply Last reply
                        0
                        • Q qcoderpro

                          Application Output tab in Qt Creator). Maybe there are some warnings there?

                          No, nothing different. Normal.

                          maybe that's the reason

                          Yes, that must be.

                          Try the MessageDialog from QtQuick.Dialogs instead of Qt

                          I created a new QtQuick project using CMake and Qt version 5.15 and tested an example of that page but get this error!
                          QQmlApplicationEngine failed to load component
                          qrc:/main.qml:3:1: module "QtQuick.Dialogs" version 1.3 is not installed

                          JKSHJ Offline
                          JKSHJ Offline
                          JKSH
                          Moderators
                          wrote on last edited by
                          #13

                          @qcoderpro said in Use dialogs in Qt 6:

                          qrc:/main.qml:3:1: module "QtQuick.Dialogs" version 1.3 is not installed*

                          If you're using Qt 6.2, then do import QtQuick.Dialogs 6.2.
                          If you're using Qt 5.15, then do import QtQuick.Dialogs 1.3.

                          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                          Q 1 Reply Last reply
                          2
                          • JKSHJ JKSH

                            @qcoderpro said in Use dialogs in Qt 6:

                            qrc:/main.qml:3:1: module "QtQuick.Dialogs" version 1.3 is not installed*

                            If you're using Qt 6.2, then do import QtQuick.Dialogs 6.2.
                            If you're using Qt 5.15, then do import QtQuick.Dialogs 1.3.

                            Q Offline
                            Q Offline
                            qcoderpro
                            wrote on last edited by
                            #14

                            @JKSH

                            My project is using Qt 5.15 and CMake as its build system, and as stated in the prior posts, that version is tested, the error message is:
                            module "QtQuick.Dialogs" version 1.3 is not installed

                            Neither Qt 5.15 nor Qt 6.2 is doing well with that element!
                            rqwe.PNG

                            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