Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QDesktopServices::openUrl segfaults (qt5, linux)
Forum Updated to NodeBB v4.3 + New Features

[Solved] QDesktopServices::openUrl segfaults (qt5, linux)

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.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.
  • T Offline
    T Offline
    t.j.a.devries
    wrote on last edited by
    #1

    Newbie, having this simple program main.cpp:

    @
    #include <QString>
    #include <QDesktopServices>
    #include <QUrl>

    int main()
    {
    QString str = "http://qt-project.org/";
    QDesktopServices::openUrl(QUrl(str));
    return 0;
    }
    @

    and this .pro file:

    @
    QT += core gui

    TARGET = openTest
    TEMPLATE = app
    CONFIG += console

    SOURCES += main.cpp
    @

    It segfaults on the openUrl statement.
    Archlinux, standard Qt5.01 package.

    What am I doing wrong?

    thanks in advance!

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

      Maybe it needs event loop to be present? I doubt it, though. Try with QUrl::fromUserInput();

      (Z(:^

      1 Reply Last reply
      0
      • T Offline
        T Offline
        toptan
        wrote on last edited by
        #3

        Well, everything :)

        Your project setup is wrong, and the code in main.cpp is also wrong.
        You can not use QDesktopServices in a console application, and you are also missing QApplication instance.

        Here is correct .pro file:
        @
        QT += core gui

        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

        TARGET = openTest
        CONFIG -= console

        TEMPLATE = app

        SOURCES += main.cpp
        @

        The correct main.cpp:
        @
        #include <QApplication>
        #include <QString>
        #include <QDesktopServices>
        #include <QUrl>

        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);
        QString str = "http://qt-project.org/";
        QDesktopServices::openUrl(QUrl(str));
        return a.exec();
        }
        @

        1 Reply Last reply
        0
        • T Offline
          T Offline
          t.j.a.devries
          wrote on last edited by
          #4

          Thanks, that solved it. Turns out the a.exec() is not needed.

          Funny thing is that in qt4 the code I originally posted did work.

          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