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. Script implementation of getItem() ignoring case of simillar items

Script implementation of getItem() ignoring case of simillar items

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 4.9k 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.
  • P Offline
    P Offline
    PaulANormanNZ
    wrote on last edited by
    #1

    Hi, I use TeXWorks (http://code.google.com/p/texworks/downloads/list) an in development GNU License project recently compiled now under Qt 7 In it there are script modules (Python and Lua) and a Qt script implementation of

    QVariant TWScriptAPI::getItem(QWidget* parent, const QString& title, const QString& label,
    const QStringList& items, int current, bool editable)
    {
    bool ok;
    QString s = QInputDialog::getItem(parent, title, label, items, current, editable, &ok);
    return ok ? QVariant(s) : QVariant();
    }

    Which has worked really well until - it seems - compilation started using the Qt 7 level, previously Qt 4 and up had been used.

    When the executable is run under Xp SP3 ...

    If items in a list are case-insensitively the same, then the first
    occurrence of a common sequence of letters seems to typecast the rest

    • they are all recognised as the same.

    ["ABCD", "abcd","Abcd","ABCD", "Efgh"]

    First three elements are always coming out as ABCD

    [ "abcd","ABCD","Abcd","ABCD", "Efgh"]

    First three elements are always coming out as abcd

    ["Abcd", "abcd","ABCD","ABCD", "Efgh"]

    First three elements are always coming out as Abcd

    Efgh is always exactly as wanted, as there is no earlier occurance.

    Use this however

    ["Abcd","abcd","ABCD","ABCD","Efgh", "EFGH"]

    And try for EFGH and you'll get Efgh.

    http://dl.dropbox.com/u/13401476/general_images/TW.getItem_fickle_problem_lowercase_returned.jpg

    As I say it doesn't happen with earlier versions.

    Is this possibly a Qt issue or should I go back to the developers please?

    Paul

    1 Reply Last reply
    0
    • B Offline
      B Offline
      baysmith
      wrote on last edited by
      #2

      I don't think this is a Qt issue. The following test application returns strings with correct case.

      @
      #include <QtCore>
      #include <QtGui>

      int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);

      QStringList items;
      items << "ABCD" << "abcd" << "Abcd" << "ABCD" << "Efgh";
      bool ok;
      do {
          QString s = QInputDialog::getItem(0, "Test QInputDialog", "Select an item.", items, 0, false, &ok);
          qDebug() << ok << s;
      } while (ok);
      

      }
      @

      Nokia Certified Qt Specialist.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PaulANormanNZ
        wrote on last edited by
        #3

        Thanks for that Bradley,

        We are currently wondering if it is possibly in
        the Qt 7 QtScript implementation?

        Paul

        1 Reply Last reply
        0
        • P Offline
          P Offline
          PaulANormanNZ
          wrote on last edited by
          #4

          The following points to a QtScript typwe issue, am I in the correct Forum still?

          This, as I have been saying did not work (though prior to curent Qt it does):

          sizeCommand = TW.getItem( null, "Text/Font Size?", "Choose Text Font/Size: ",
          ["Abcd","abcd","ABCD","ABCD","Efgh", "EFGH"] , 1 , true ) ;

          And this did not work:

          var optionsList = ["Abcd","abcd","ABCD","ABCD","Efgh", "EFGH"];

          sizeCommand = TW.getItem( null, "Text/Font Size?", "Choose Text Font/Size: ",
          optionsList , 1 , true ) ;

          This bypasses the problem and works.
          Explicit old fashioned array declaration constructor.

          var optionsList = new Array("Abcd","abcd","ABCD","ABCD","Efgh", "EFGH");

          sizeCommand = TW.getItem( null, "Text/Font Size?", "Choose Text Font/Size: ", optionsList , 1 , true ) ;

          As far as I know all the above are valid ECMA (QtScript).

          Paul

          1 Reply Last reply
          0
          • B Offline
            B Offline
            baysmith
            wrote on last edited by
            #5

            I don't think it is a QtScript issue either. Here is a test application which works.

            @
            #include <QtCore>
            #include <QtGui>
            #include <QtScript>

            class TW: public QObject
            {
            Q_OBJECT
            public:
            TW(QObject *parent = 0) : QObject(parent) {}
            Q_INVOKABLE QVariant getItem(const QString& title, const QString& label,
            const QStringList& items, int current = 0, bool editable = true);
            };

            QVariant TW::getItem(const QString& title, const QString& label,
            const QStringList& items, int current, bool editable)
            {
            bool ok;
            QString s = QInputDialog::getItem(0, title, label, items, current, editable, &ok);
            return ok ? QVariant(s) : QVariant();
            }

            int main(int argc, char *argv[])
            {
            QApplication a(argc, argv);

            QScriptEngine engine;
            TW *tw = new TW;
            QScriptValue objectValue = engine.newQObject(tw);
            engine.globalObject().setProperty("TW", objectValue);
            QScriptValue result;
            do {
                result = engine.evaluate("TW.getItem('Test 1', 'Test 1', ['ABCD', 'abcd', 'Abcd', 'ABCD', 'Efgh'])");
                qDebug() << result.toString();
                if (result.isUndefined()) break;
                result = engine.evaluate("var optionsList = ['ABCD', 'abcd', 'Abcd', 'ABCD', 'Efgh']; "
                                         "TW.getItem('Test 2', 'Test 2', optionsList)");
                qDebug() << result.toString();
                if (result.isUndefined()) break;
                result = engine.evaluate("var optionsList = new Array('ABCD', 'abcd', 'Abcd', 'ABCD', 'Efgh'); "
                                         "TW.getItem('Test 3', 'Test 3', optionsList)");
                qDebug() << result.toString();
            } while (!result.isUndefined());
            
            return 0;
            

            }

            #include "main.moc"
            @

            Nokia Certified Qt Specialist.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              PaulANormanNZ
              wrote on last edited by
              #6

              Thanks Bradley,

              Which version of Qt are you building/compiling under please?

              var optionsList = new Array("Abcd","abcd","ABCD","ABCD","Efgh", "EFGH");

              ... Only has it solved sometimes - fickle.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                baysmith
                wrote on last edited by
                #7

                Qt 4.7.0, Windows

                Nokia Certified Qt Specialist.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  PaulANormanNZ
                  wrote on last edited by
                  #8

                  Thanks for that Bradly,

                  I've now replicated this error on different native Win Xp Pro Sp3 machines, using a clean install of the project.

                  Talking with the most active developer on our project, nothing recognisably of relevance has changed since it all was working correctly, other than using Qt 4.7 and cross compiling form Ubuntu for Win. b.t.w it all works fine for him in a Windows emu box under Ubuntu.

                  Our situation is not applying the coding directly to the library as in the code experiments here, but reading it in from disk as a stored .js

                  Paul

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    baysmith
                    wrote on last edited by
                    #9

                    Any idea why that is causing a problem? It doesn't sound to me like it should.

                    (Bradley, not Bradly :) )

                    Nokia Certified Qt Specialist.

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      PaulANormanNZ
                      wrote on last edited by
                      #10

                      Dear Bradley - sorry about the previous spelling,

                      Stefan Löffler on TeXworks development, has built your code under the normal TeXworks build process and we are testing it now to try and solve the issue.

                      http://web.student.tuwien.ac.at/~e0325258/projects/c/texworks/lowercase-array.exe

                      Paul

                      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