PDA

View Full Version : Problem with a dynamicCall and a Qstring variable



jokinb
22nd October 2010, 14:48
I´m working in a program with scanning capabilities. For this work I use an ActiveX control from Pegasus. To this ActiveX control I make several dynamicCall(). All work fine , but I have find a problem.

the following code:


QString str;
QString str2;
QList<QVariant> vars;
str2=QInputDialog::getText(this,"Write file´s name","Name: ");
vars<<str2;
str="SaveFile(QString)";
qDebug()<<str;
qDebug()<<str2;
qDebug()<<vars;
wmp->dynamicCall(str.toLatin1(),vars);

creates the folowing debugger output:


"SaveFile(QString)"
"c:\nnimagen"
(QVariant(QString, "c:\nnimagen") )

All is ok and the dynamicCall works fine. I can save the scanned imagen.

But this other code:


QString str;
QString str2;
QList<QVariant> vars;
str2="c:\nnimagen.bmp";
vars<<str2;
str="SaveFile(QString)";
qDebug()<<str;
qDebug()<<str2;
qDebug()<<vars;
wmp->dynamicCall(str.toLatin1(),vars);

creates this other debugger output:


"SaveFile(QString)"
"c:
nnimagen.bmp"
(QVariant(QString, "c:
nimagen.bmp") )

In this case the "\n"caracters (from "c:\nnimage.bmp") are taken like a escape sequence, and the dynamicCall() produces an error.

If it is supposed that QInputDialog::getText returns a QString, ¿how is it posible? ?What is the diffecence betwen str2="c:\nnimagen.bmp" and str2=QInputDialog::getText(.......).

Why this error happens?.
How I must initializates the str2 QString?

high_flyer
22nd October 2010, 15:25
Try this:

str2=QInputDialog::getText(this,"Write file´s name","Name: ").replace(QString("\"),QString("\\"));

jokinb
22nd October 2010, 17:02
Sorry , high_flyer. The str2=QInputDialog::getText(......) method work fine.
The problem appear when I create a str2 QString with this method:


QString str2;
str2="c:\nnimagen.bmp";

The "\n" sequence is taked as a escape sequence.
It is not a way to make this initialization without this error.

Added after 29 minutes:

Thanks to high_flyer one of the questions is resolved.

We must initializate the str2 Qstring in this manner:


QString str2;
str2="c:\\nnimagen.bmp";

In this maner the \\ is considered as a escape sequence and converted to a singel \.

Thanks

high_flyer
23rd October 2010, 16:46
one of the questions is resolved

What was the other question?

jokinb
24th October 2010, 07:44
So it is supossed that the QInputDialog::getText method do this conversion internally?

high_flyer
25th October 2010, 08:11
No.
Why should it?
QInputDialog is just a convenience class for simple input.
It knows nothing about paths.