Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    QGuiApplication crashed when passing Unicode string like Thai parameter?

    General and Desktop
    qguiapplication unicode parameter qquickview
    3
    11
    3016
    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.
    • D
      dhuta last edited by dhuta

      I have a gui app, which want to grab an image of QQuickView, though gui app, i want to control it in terminal. At the same time, the only component in qml passed to QQuickView is just a Text component . I want to pass my wantted string to the Text's text property. But, i find it probably crash when i pass in some unicode string like Thai. My OS is win7, Qt5.3.1. The app crashs in QCoreApplication::arguments(). Or the demand is rediculous?

      How to solve it? Anyone can help me?

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Can you reproduce that with a minimal compilable example ? What is the string that makes your application crash ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        D 1 Reply Last reply Reply Quote 0
        • D
          dhuta @SGaist last edited by dhuta

          @SGaist Sample code is at https://github.com/EightFingerDhuta/qt/tree/master/crashArgs。
          Test string is "สวัสดี" in thai. But it will be ok when pass "你好" etc.

          This simplified sample runs ok in qtcreator (parameter passed in qtcreator), but fails when run it in cmd terminal after deploy it.

          In fact, my original app even cannot run in qtcreator. When delete all build files manually and rebuild it, it can run successfully only once.

          I 1 Reply Last reply Reply Quote 0
          • I
            ileonte @dhuta last edited by

            @dhuta your app is crashing because argv0 is not terminated by a NULL pointer. You need to declare it as char *argv0[argc0 + 1] and then add argv0[i] = NULL; after the for loop in which you copy from argv to argv0.

            D 1 Reply Last reply Reply Quote 0
            • D
              dhuta @ileonte last edited by dhuta

              @ileonte It really a bug. But the sample code still failed when i not modify these parameters or add the NULL pointer as you said.

              I 1 Reply Last reply Reply Quote 0
              • I
                ileonte @dhuta last edited by

                @dhuta what I meant to say is add argv0[argc + 2] = NULL;. That part about argv0[i] = NULL; is wrong. Your code should look like this:

                    int argc0 = argc + 2;
                    char *argv0[argc0 + 1];
                
                    for (int i = 0; i < argc; i++) {
                        argv0[i] = argv[i];
                    }
                
                    argv0[argc] = arg1;
                    argv0[argc + 1] = arg2;
                    argv0[argc + 2] = NULL;
                
                D 1 Reply Last reply Reply Quote 0
                • D
                  dhuta @ileonte last edited by

                  @ileonte Yeah. I just add it exactly as you do. But the sample still crash.

                  I 1 Reply Last reply Reply Quote 0
                  • I
                    ileonte @dhuta last edited by

                    @dhuta Where is the call stack for the crash originating from ? Is it the QApplication constructor or the parser.process(app); call ? Also can you please push the modified code to GitHub so I can have another look ?

                    D 1 Reply Last reply Reply Quote 0
                    • D
                      dhuta @ileonte last edited by

                      @ileonte I have already push the modified code. When i run it under debug mode, it crashs with a message: ASSERT: "allArguments.size() == origArgc" in file kernel\qtcoreapplication.cpp line 2191. I google it, it seems that this is an already known bug: https://bugreports.qt.io/browse/QTBUG-30330. Maybe i should found another way to get my wanted result.

                      Thanks a lot !

                      I 1 Reply Last reply Reply Quote 0
                      • I
                        ileonte @dhuta last edited by

                        @dhuta That bug is marked as closed, maybe you could try updating to a newer version of Qt.

                        D 1 Reply Last reply Reply Quote 0
                        • D
                          dhuta @ileonte last edited by

                          @ileonte Uh, i must use Qt5.3.1, coz our project demands this version....I think i have to read file to get target text string.

                          Anyway, thank you~ :)

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post