December 9, 2010

PaulANormanNZ PaulANormanNZ
Lab Rat
5 posts

Script implementation of getItem() ignoring case of simillar items

 

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

9 replies

December 9, 2010

Bradley Bradley
Lab Rat
314 posts

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

  1. #include <QtCore>
  2. #include <QtGui>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6.     QApplication app(argc, argv);
  7.  
  8.     QStringList items;
  9.     items << "ABCD" << "abcd" << "Abcd" << "ABCD" << "Efgh";
  10.     bool ok;
  11.     do {
  12.         QString s = QInputDialog::getItem(0, "Test QInputDialog", "Select an item.", items, 0, false, &ok);
  13.         qDebug() << ok << s;
  14.     } while (ok);
  15.  
  16. }

 Signature 

Nokia Certified Qt Specialist.

December 9, 2010

PaulANormanNZ PaulANormanNZ
Lab Rat
5 posts

Thanks for that Bradley,

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

Paul

December 9, 2010

PaulANormanNZ PaulANormanNZ
Lab Rat
5 posts

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

December 9, 2010

Bradley Bradley
Lab Rat
314 posts

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

  1. #include <QtCore>
  2. #include <QtGui>
  3. #include <QtScript>
  4.  
  5. class TW: public QObject
  6. {
  7.     Q_OBJECT
  8. public:
  9.     TW(QObject *parent = 0) : QObject(parent) {}
  10.     Q_INVOKABLE QVariant getItem(const QString& title, const QString& label,
  11.                                  const QStringList& items, int current = 0, bool editable = true);
  12. };
  13.  
  14. QVariant TW::getItem(const QString& title, const QString& label,
  15.                      const QStringList& items, int current, bool editable)
  16. {
  17.     bool ok;
  18.     QString s = QInputDialog::getItem(0, title, label, items, current, editable, &ok);
  19.     return ok ? QVariant(s) : QVariant();
  20. }
  21.  
  22. int main(int argc, char *argv[])
  23. {
  24.     QApplication a(argc, argv);
  25.    
  26.     QScriptEngine engine;
  27.     TW *tw = new TW;
  28.     QScriptValue objectValue = engine.newQObject(tw);
  29.     engine.globalObject().setProperty("TW", objectValue);
  30.     QScriptValue result;
  31.     do {
  32.         result = engine.evaluate("TW.getItem('Test 1', 'Test 1', ['ABCD', 'abcd', 'Abcd', 'ABCD', 'Efgh'])");
  33.         qDebug() << result.toString();
  34.         if (result.isUndefined()) break;
  35.         result = engine.evaluate("var optionsList = ['ABCD', 'abcd', 'Abcd', 'ABCD', 'Efgh']; "
  36.                                  "TW.getItem('Test 2', 'Test 2', optionsList)");
  37.         qDebug() << result.toString();
  38.         if (result.isUndefined()) break;
  39.         result = engine.evaluate("var optionsList = new Array('ABCD', 'abcd', 'Abcd', 'ABCD', 'Efgh'); "
  40.                                  "TW.getItem('Test 3', 'Test 3', optionsList)");
  41.         qDebug() << result.toString();
  42.     } while (!result.isUndefined());
  43.    
  44.     return 0;
  45. }
  46.  
  47. #include "main.moc"

 Signature 

Nokia Certified Qt Specialist.

December 9, 2010

PaulANormanNZ PaulANormanNZ
Lab Rat
5 posts

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.

December 9, 2010

Bradley Bradley
Lab Rat
314 posts

Qt 4.7.0, Windows

 Signature 

Nokia Certified Qt Specialist.

December 11, 2010

PaulANormanNZ PaulANormanNZ
Lab Rat
5 posts

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

December 11, 2010

Bradley Bradley
Lab Rat
314 posts

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

(Bradley, not Bradly :) )

 Signature 

Nokia Certified Qt Specialist.

December 15, 2010

PaulANormanNZ PaulANormanNZ
Lab Rat
5 posts

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

 
  ‹‹ QComboBox autocomplete automatically changes edittext.      non GUI thread use ››

You must log in to post a reply. Not a member yet? Register here!