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
-
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);
}
@ -
Thanks for that Bradley,
We are currently wondering if it is possibly in
the Qt 7 QtScript implementation?Paul
-
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
-
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"
@ -
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.
-
Qt 4.7.0, Windows
-
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
-
Any idea why that is causing a problem? It doesn't sound to me like it should.
(Bradley, not Bradly :) )
-
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