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. working example of QMessage

working example of QMessage

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 366 Views
  • 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.
  • B Offline
    B Offline
    Basile_Starynkevitch
    wrote on last edited by
    #1

    Hello all,

    This is in the context of the RefPerSys project (GPLv3+) which has its own forum. It aims to become some domain specific language implementation (e.g. expert system shell) for symbolic artificial intelligence. It is a research project, so localization is not relevant for us, so we don't use Qt tr thing. On Ubuntu 21.04 (x86/64) only (we don't care about non Debian-like x86-64 OSes). Source repository is here. Our latest git commit is c57127 and right now I compile with clang-12 and clang++-12 (often I compile with a GCC 11 which I compiled from its source code).

    The command pkg-config --modversion Qt5Widgets gives 5.15.2 and I assume that for other Qt5 packages the same version is given (I checked for Qt5Core).

    RefPerSys is coded in an unusual way. In most cases, it does not even use or link Qt. It is built using GNU make

    However, when RefPerSys is run as ./refpersys --Qt -AGUI,WEB it is dlopen-ing the ./tempgui-qrps.so shared object. That shared object is the only Qt related thing. The source code for it is in two C++ files: tempgui-qrps.hh and tempgui-qrps.cc and the Qt moc command is explicitly run by make, when needed for tempgui-qrps.so.

    In RefPerSys' C++ file tempgui-qrps.cc I have a C++ Qt slot RpsTemp_MainWindow::do_enter_shown_object (near line 320). In that function I am trying to code (full capital things are macros, see our file refpersys.hh):

    if (!_f.showob) {		// first case: no shown object, should display a Qt dialog
      char warntitle[64];
      memset (warntitle, 0, sizeof(warntitle));
      snprintf (warntitle, sizeof(warntitle), "no object for window #%d", mainwin_rank);
      RPS_DEBUG_LOG(GUI, "RpsTemp_MainWindow::do_enter_shown_object lacks no shown object in window#" << mainwin_rank 
      	  << " for " << obshowstring << std::endl
            << RPS_FULL_BACKTRACE_HERE(1, "RpsTemp_MainWindow::do_enter_shown_object - none"));
      int q= -1;
      QMessageBox qmsg;
      if (obshowstring[0] == '_') {
        QString warndetail;
        warndetail = "There is no object of oid <tt>";
        warndetail += obshowstring;
        warndetail += "</tt>";
        QMessageBox::warning(this, QString(warntitle),
      			  warndetail);
      }
      /*
      else
        (void) warnmsg.warning(this, warntitle,
      		 "There is no object named <i>" + obshowstring + "</i>");
      */
      return;
    }
    

    For some reason, this C++ code don't compile. I am getting the following error messages

    ^
    tempgui-qrps.cc:360:18: error: no viable overloaded '+='
         warndetail += obshowstring;
         ~~~~~~~~~~ ^  ~~~~~~~~~~~~
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:230:1: note: candidate function not viable: no known conversion from 'QString' to 'qfloat16 &' for 1st argument
    QF16_MAKE_ARITH_OP(long double)
    ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:226:5: note: expanded from macro 'QF16_MAKE_ARITH_OP'
       QF16_MAKE_ARITH_OP_EQ_FP(FP, +=, +) \
       ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:219:22: note: expanded from macro 'QF16_MAKE_ARITH_OP_EQ_FP'
       inline qfloat16& operator OP_EQ(qfloat16& lhs, FP rhs) noexcept \
                        ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:231:1: note: candidate function not viable: no known conversion from 'QString' to 'qfloat16 &' for 1st argument
    QF16_MAKE_ARITH_OP(double)
    ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:226:5: note: expanded from macro 'QF16_MAKE_ARITH_OP'
       QF16_MAKE_ARITH_OP_EQ_FP(FP, +=, +) \
       ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:219:22: note: expanded from macro 'QF16_MAKE_ARITH_OP_EQ_FP'
       inline qfloat16& operator OP_EQ(qfloat16& lhs, FP rhs) noexcept \
                        ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:232:1: note: candidate function not viable: no known conversion from 'QString' to 'qfloat16 &' for 1st argument
    QF16_MAKE_ARITH_OP(float)
    ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:226:5: note: expanded from macro 'QF16_MAKE_ARITH_OP'
       QF16_MAKE_ARITH_OP_EQ_FP(FP, +=, +) \
       ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:219:22: note: expanded from macro 'QF16_MAKE_ARITH_OP_EQ_FP'
       inline qfloat16& operator OP_EQ(qfloat16& lhs, FP rhs) noexcept \
                        ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qstringbuilder.h:474:13: note: candidate template ignored: could not match 'QStringBuilder' against 'basic_string'
    QByteArray &operator+=(QByteArray &a, const QStringBuilder<A, B> &b)
               ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qstringbuilder.h:481:10: note: candidate template ignored: could not match 'QStringBuilder' against 'basic_string'
    QString &operator+=(QString &a, const QStringBuilder<A, B> &b)
            ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:560:21: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'QChar' for 1st argument
       inline QString &operator+=(QChar c) {
                       ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:568:21: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'QChar::SpecialCharacter' for 1st argument
       inline QString &operator+=(QChar::SpecialCharacter c) { return append(QChar(c)); }
                       ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:569:21: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'const QString' for 1st argument
       inline QString &operator+=(const QString &s) { return append(s); }
                       ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:570:21: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'const QStringRef' for 1st argument
       inline QString &operator+=(const QStringRef &s) { return append(s); }
                       ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:571:21: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'QLatin1String' for 1st argument
       inline QString &operator+=(QLatin1String s) { return append(s); }
                       ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:572:21: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'QStringView' for 1st argument
       inline QString &operator+=(QStringView s) { return append(s); }
                       ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:861:40: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'const char *' for 1st argument
       inline QT_ASCII_CAST_WARN QString &operator+=(const char *s)
                                          ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:863:40: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'const QByteArray' for 1st argument
       inline QT_ASCII_CAST_WARN QString &operator+=(const QByteArray &s)
                                          ^
    /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:865:40: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'char' for 1st argument
       inline QT_ASCII_CAST_WARN QString &operator+=(char c)
                                          ^
    

    The compiler is the packaged clang++-12, see this message for details.

    What am I doing wrong?

    Thanks for your help.

    Basile Starynkevitch - http://starynkevitch.net/Basile/ email basile@starynkevitch.net
    (near Paris, in France)

    Basile Starynkevitch <basile@starynkevitch.net>
    (only mine opinions / les opinions sont miennes uniquement)
    92340 Bourg-la-Reine, France
    web page: starynkevitch.net/Basile/
    See/voir: https://github.com/RefPerSys/RefPerSys

    jsulmJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You can't add a std::string to a QString without a conversion (I would guess that obshowstring is a std::string) - you have to convert it first.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • B Basile_Starynkevitch

        Hello all,

        This is in the context of the RefPerSys project (GPLv3+) which has its own forum. It aims to become some domain specific language implementation (e.g. expert system shell) for symbolic artificial intelligence. It is a research project, so localization is not relevant for us, so we don't use Qt tr thing. On Ubuntu 21.04 (x86/64) only (we don't care about non Debian-like x86-64 OSes). Source repository is here. Our latest git commit is c57127 and right now I compile with clang-12 and clang++-12 (often I compile with a GCC 11 which I compiled from its source code).

        The command pkg-config --modversion Qt5Widgets gives 5.15.2 and I assume that for other Qt5 packages the same version is given (I checked for Qt5Core).

        RefPerSys is coded in an unusual way. In most cases, it does not even use or link Qt. It is built using GNU make

        However, when RefPerSys is run as ./refpersys --Qt -AGUI,WEB it is dlopen-ing the ./tempgui-qrps.so shared object. That shared object is the only Qt related thing. The source code for it is in two C++ files: tempgui-qrps.hh and tempgui-qrps.cc and the Qt moc command is explicitly run by make, when needed for tempgui-qrps.so.

        In RefPerSys' C++ file tempgui-qrps.cc I have a C++ Qt slot RpsTemp_MainWindow::do_enter_shown_object (near line 320). In that function I am trying to code (full capital things are macros, see our file refpersys.hh):

        if (!_f.showob) {		// first case: no shown object, should display a Qt dialog
          char warntitle[64];
          memset (warntitle, 0, sizeof(warntitle));
          snprintf (warntitle, sizeof(warntitle), "no object for window #%d", mainwin_rank);
          RPS_DEBUG_LOG(GUI, "RpsTemp_MainWindow::do_enter_shown_object lacks no shown object in window#" << mainwin_rank 
          	  << " for " << obshowstring << std::endl
                << RPS_FULL_BACKTRACE_HERE(1, "RpsTemp_MainWindow::do_enter_shown_object - none"));
          int q= -1;
          QMessageBox qmsg;
          if (obshowstring[0] == '_') {
            QString warndetail;
            warndetail = "There is no object of oid <tt>";
            warndetail += obshowstring;
            warndetail += "</tt>";
            QMessageBox::warning(this, QString(warntitle),
          			  warndetail);
          }
          /*
          else
            (void) warnmsg.warning(this, warntitle,
          		 "There is no object named <i>" + obshowstring + "</i>");
          */
          return;
        }
        

        For some reason, this C++ code don't compile. I am getting the following error messages

        ^
        tempgui-qrps.cc:360:18: error: no viable overloaded '+='
             warndetail += obshowstring;
             ~~~~~~~~~~ ^  ~~~~~~~~~~~~
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:230:1: note: candidate function not viable: no known conversion from 'QString' to 'qfloat16 &' for 1st argument
        QF16_MAKE_ARITH_OP(long double)
        ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:226:5: note: expanded from macro 'QF16_MAKE_ARITH_OP'
           QF16_MAKE_ARITH_OP_EQ_FP(FP, +=, +) \
           ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:219:22: note: expanded from macro 'QF16_MAKE_ARITH_OP_EQ_FP'
           inline qfloat16& operator OP_EQ(qfloat16& lhs, FP rhs) noexcept \
                            ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:231:1: note: candidate function not viable: no known conversion from 'QString' to 'qfloat16 &' for 1st argument
        QF16_MAKE_ARITH_OP(double)
        ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:226:5: note: expanded from macro 'QF16_MAKE_ARITH_OP'
           QF16_MAKE_ARITH_OP_EQ_FP(FP, +=, +) \
           ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:219:22: note: expanded from macro 'QF16_MAKE_ARITH_OP_EQ_FP'
           inline qfloat16& operator OP_EQ(qfloat16& lhs, FP rhs) noexcept \
                            ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:232:1: note: candidate function not viable: no known conversion from 'QString' to 'qfloat16 &' for 1st argument
        QF16_MAKE_ARITH_OP(float)
        ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:226:5: note: expanded from macro 'QF16_MAKE_ARITH_OP'
           QF16_MAKE_ARITH_OP_EQ_FP(FP, +=, +) \
           ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qfloat16.h:219:22: note: expanded from macro 'QF16_MAKE_ARITH_OP_EQ_FP'
           inline qfloat16& operator OP_EQ(qfloat16& lhs, FP rhs) noexcept \
                            ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qstringbuilder.h:474:13: note: candidate template ignored: could not match 'QStringBuilder' against 'basic_string'
        QByteArray &operator+=(QByteArray &a, const QStringBuilder<A, B> &b)
                   ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qstringbuilder.h:481:10: note: candidate template ignored: could not match 'QStringBuilder' against 'basic_string'
        QString &operator+=(QString &a, const QStringBuilder<A, B> &b)
                ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:560:21: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'QChar' for 1st argument
           inline QString &operator+=(QChar c) {
                           ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:568:21: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'QChar::SpecialCharacter' for 1st argument
           inline QString &operator+=(QChar::SpecialCharacter c) { return append(QChar(c)); }
                           ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:569:21: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'const QString' for 1st argument
           inline QString &operator+=(const QString &s) { return append(s); }
                           ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:570:21: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'const QStringRef' for 1st argument
           inline QString &operator+=(const QStringRef &s) { return append(s); }
                           ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:571:21: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'QLatin1String' for 1st argument
           inline QString &operator+=(QLatin1String s) { return append(s); }
                           ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:572:21: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'QStringView' for 1st argument
           inline QString &operator+=(QStringView s) { return append(s); }
                           ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:861:40: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'const char *' for 1st argument
           inline QT_ASCII_CAST_WARN QString &operator+=(const char *s)
                                              ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:863:40: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'const QByteArray' for 1st argument
           inline QT_ASCII_CAST_WARN QString &operator+=(const QByteArray &s)
                                              ^
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:865:40: note: candidate function not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'char' for 1st argument
           inline QT_ASCII_CAST_WARN QString &operator+=(char c)
                                              ^
        

        The compiler is the packaged clang++-12, see this message for details.

        What am I doing wrong?

        Thanks for your help.

        Basile Starynkevitch - http://starynkevitch.net/Basile/ email basile@starynkevitch.net
        (near Paris, in France)

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Basile_Starynkevitch First: why do you create a QMessageBox instance if you later call static method (QMessageBox::warning)?
        Regarding errors: what type is obshowstring?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Basile_Starynkevitch
          wrote on last edited by Basile_Starynkevitch
          #4

          As a general point, I prefer using usual C++ std::string (they all are UTF8 encoded), or C const char* string (UTF8). The reason is more political than technical: I am afraid that in 2021, funding agencies prefer Web interfaces to Qt ones (on desktops or laptops) for software having several human users at once.

          Also, RefPerSys being today a research project, efficiency is not a priority, and losing CPU time in lots of std::string to QString conversion (and vice versa) is now (july 2021) acceptable.

          Our long term vision is to generate C++ code (from our higher-level declarative formalism, expert system like). Ideally, like Pitrat explains in his Artificial Beings: the Conscience of a Conscious Machine book (ISBN 978-1848211018), we want to generate all the C++ code of RefPerSys. Of course, that is an ambitious goal, and we are very far from it. Sadly, in july 2021, we have very few generated C++ lines. BTW, Jacques Pitrat was the director of my PhD jury, defended in Paris in 1990.

          The local variable obshowstring is declared as std::string obshowstring in file tempgui-qrps.cc, for commit 7fa10ba9cd62 in line 331

          Regards, and thanks for your help.

          Basile Starynkevitch - near Paris in France

          PS. Off-topic: I am interested in any HorizonEurope submission which could fund RefPerSys. The RefPerSys website mentions some potential calls (e.g. HORIZON-CL2-DEMOCRACY-2022-01-01, HORIZON-CL2-DEMOCRACY-2022-01-05, HORIZON-CL2-DEMOCRACY-2022-01-06, HORIZON-CL2-HERITAGE-2022-01-03, HORIZON-CL2-HERITAGE-2022-01-04, HORIZON-CL2-HERITAGE-2022-01-06, HORIZON-HLTH-2021-STAYHLTH-01-02, HORIZON-HLTH-2022-STAYHLTH-01-01, HORIZON-HLTH-2022-STAYHLTH-01-04, HORIZON-HLTH-2022-STAYHLTH-02-01 but there could be others.
          Contact me then by email to both basile@starynkevitch.net (personal email) and to basile.starynkevitch@cea.fr (professional email at CEA LIST)

          Basile Starynkevitch <basile@starynkevitch.net>
          (only mine opinions / les opinions sont miennes uniquement)
          92340 Bourg-la-Reine, France
          web page: starynkevitch.net/Basile/
          See/voir: https://github.com/RefPerSys/RefPerSys

          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