UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    SOLVED: How do I get my app to launch the web browser?

    Scheduled Pinned Locked Moved App Development
    21 Posts 6 Posters 6.4k Views 3 Watching
    Loading More Posts
    • 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.
    • arubislanderA Offline
      arubislander
      last edited by

      There is a thread somewhere on this forum concerning launching the browser from QML. I do not have the opportunity to search for it a.t.m. Might do so when I get home, if no one beats me to it. I am thinking something similar must be posible from C++ πŸ€”

      πŸ‡¦πŸ‡Ό πŸ‡³πŸ‡± πŸ‡ΊπŸ‡Έ πŸ‡ͺπŸ‡Έ
      Happily running Ubuntu Touch
      JingPad (24.04-1.x daily)
      OnePlus Nord N10 5G (24.04-2.x daily)
      PinePhone OG (20.04)
      Meizu Pro 5 (16.04 DEV)

      1 Reply Last reply Reply Quote 0
      • AppLeeA Offline
        AppLee
        last edited by

        From QML, I have this working :

         Action {
                iconName: "info"
                onTriggered: Qt.openUrlExternally("https://www.domoticz.com/")
              }
        

        I don't remember what to include to have Qt.openUrlExternally() in your C++ code.
        Might help...

        dobeyD 1 Reply Last reply Reply Quote 0
        • dobeyD Offline
          dobey @AppLee
          last edited by

          @AppLee One would need to use https://doc.qt.io/qt-5.9/qdesktopservices.html#openUrl

          CraigC 1 Reply Last reply Reply Quote 1
          • CraigC Offline
            Craig @dobey
            last edited by

            @dobey You are right. I was testing QDesktopServices::openUrl when you posted this.

            My C++/SDL app launches the morph web browser. Here's how to make a C++/SDL app launch the web browser in Ubuntu Touch:

            Step 1:
            You need to add these to your CMakeLists.txt:
            (You may have more than one CMakeList.txt file and some of the code lines below will go in different CMakeList.txt files.)

            (Add these lines below after "project(...)" and "cmake_minimum_required(..)")

            find_package(Qt5Core)
            find_package(Qt5Qml)
            find_package(Qt5Quick)
            

            (Add this line below after "execute_process(... OUTPUT_VARIABLE ARCH_TRIPLET ...)" )

            set(QT_IMPORTS_DIR "lib/${ARCH_TRIPLET}")
            

            (Add this line below after "add_executable(... main.cpp ...)" )

            qt5_use_modules(YOURPROJECTNAMEHERE Gui Qml Quick QuickControls2)
            

            Replace YOURPROJECTNAMEHERE with your project name.

            Step 2:
            Put these headers near the top of main.h/main.cpp:

            #include <QGuiApplication>
            #include <QDesktopServices>
            #include <QUrl>
            

            Put this at the top of main():

            QGuiApplication *app = new QGuiApplication(argc, (char**)argv);
            

            Near the end of main(), replace "return 0;" with this:

            return app->exec();
            

            Step 3:
            And now for the magic... Somewhere in your C++ code, make your link:

            if ( event.type == SDL_FINGERDOWN )
            {
                QDesktopServices::openUrl(QUrl("https://forums.ubports.com"));
            }
            

            If you have any comments, suggestions or ways to improve this code, let me know. Thank you all for your help.

            dobeyD 1 Reply Last reply Reply Quote 3
            • dobeyD Offline
              dobey @Craig
              last edited by

              @Craig said in How do I get my app to launch the web browser?:

              find_package(Qt5Core)
              find_package(Qt5Qml)
              find_package(Qt5Quick)

              You don't need Quick or Qml here. Though I think you will need Gui. Also it'd be better to do:

              find_package(Qt5 COMPONENTS Core Gui)
              

              set(QT_IMPORTS_DIR "lib/${ARCH_TRIPLET}")

              You don't need this, as you aren't using any QML parts.

              qt5_use_modules(YOURPROJECTNAMEHERE Gui Qml Quick QuickControls2)

              For this, you should instead just add

              Qt5::Core
              Qt5::Gui
              

              to the list of libraries you pass to the target_link_libraries() call.

              I'm also not sure if you need a QApplication thread running at all for this. If possible, it's probably better to avoid having to integrate the Qt main loop and SDL. If it is needed though, it would probably be better to use QCoreApplication or QApplication instead, if possible.

              CraigC 1 Reply Last reply Reply Quote 1
              • CraigC Offline
                Craig @dobey
                last edited by Craig

                @dobey I made the simplifications to the CMakeLists.txt file that you suggested. It's working, thank you!

                In the last part of your previous message, you wrote:

                I'm also not sure if you need a QApplication thread running at all for this. If possible, it's probably better to avoid having to integrate the Qt main loop and SDL. If it is needed though, it would probably be better to use QCoreApplication or QApplication instead, if possible.

                I think you meant something other than QApplication the second time you mentioned it. Which library instead of QApplication?

                I tried it with these in main():

                QCoreApplication a(argc, args);
                return a.exec();
                

                Although clickable compiled and it ran, QDesktopServices::openUrl() did not work at all. The browser would not launch.

                dobeyD 1 Reply Last reply Reply Quote 0
                • dobeyD Offline
                  dobey @Craig
                  last edited by

                  @Craig said in How do I get my app to launch the web browser?:

                  Although clickable compiled and it ran, QDesktopServices::openUrl() did not work at all. The browser would not launch.

                  OK. I suppose you do need to use QGuiApplication then.

                  1 Reply Last reply Reply Quote 0
                  • CraigC Offline
                    Craig
                    last edited by

                    So, just to recap, here's how to make a C++ app launch the web browser in Ubuntu Touch:

                    Step 1:
                    You need to add/change these in your CMakeLists.txt:

                    find_package(Qt5 COMPONENTS Core Gui)
                    target_link_libraries(YOURPROJECTNAMEHERE ... Qt5::Core Qt5::Gui)
                    

                    Step 2:
                    Put these headers near the top of main.h/main.cpp:

                    #include <QGuiApplication>
                    #include <QDesktopServices>
                    #include <QUrl>
                    

                    Put this at the top of main():

                    QGuiApplication *app = new QGuiApplication(argc, (char**)argv);
                    

                    Near the end of main(), replace "return 0;" with this:

                    return app->exec();
                    

                    Step 3:
                    Somewhere in your C++ code, when the app user clicks on your button, call this:

                    QDesktopServices::openUrl(QUrl("https://forums.ubports.com"));
                    
                    lduboeufL 1 Reply Last reply Reply Quote 3
                    • lduboeufL Offline
                      lduboeuf @Craig
                      last edited by

                      @Craig thanks for sharing πŸ™‚

                      1 Reply Last reply Reply Quote 0
                      • L Offline
                        L-00997
                        last edited by

                        This post is deleted!
                        1 Reply Last reply Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better πŸ’—

                        Register Login
                        • First post
                          Last post