Results 1 to 6 of 6

Thread: Problem with a dynamicCall and a Qstring variable

  1. #1
    Join Date
    Oct 2010
    Posts
    7
    Qt products
    Qt4

    Default Problem with a dynamicCall and a Qstring variable

    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:

    Qt Code:
    1. QString str;
    2. QString str2;
    3. QList<QVariant> vars;
    4. str2=QInputDialog::getText(this,"Write file´s name","Name: ");
    5. vars<<str2;
    6. str="SaveFile(QString)";
    7. qDebug()<<str;
    8. qDebug()<<str2;
    9. qDebug()<<vars;
    10. wmp->dynamicCall(str.toLatin1(),vars);
    To copy to clipboard, switch view to plain text mode 

    creates the folowing debugger output:

    Qt Code:
    1. "SaveFile(QString)"
    2. "c:\nnimagen"
    3. (QVariant(QString, "c:\nnimagen") )
    To copy to clipboard, switch view to plain text mode 

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

    But this other code:

    Qt Code:
    1. QString str;
    2. QString str2;
    3. QList<QVariant> vars;
    4. str2="c:\nnimagen.bmp";
    5. vars<<str2;
    6. str="SaveFile(QString)";
    7. qDebug()<<str;
    8. qDebug()<<str2;
    9. qDebug()<<vars;
    10. wmp->dynamicCall(str.toLatin1(),vars);
    To copy to clipboard, switch view to plain text mode 

    creates this other debugger output:

    Qt Code:
    1. "SaveFile(QString)"
    2. "c:
    3. nnimagen.bmp"
    4. nimagen.bmp") )
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with a dynamicCall and a Qstring variable

    Try this:
    Qt Code:
    1. str2=QInputDialog::getText(this,"Write file´s name","Name: ").replace(QString("\"),QString("\\"));
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Oct 2010
    Posts
    7
    Qt products
    Qt4

    Default Re: Problem with a dynamicCall and a Qstring variable

    Sorry , high_flyer. The str2=QInputDialog::getText(......) method work fine.
    The problem appear when I create a str2 QString with this method:

    Qt Code:
    1. QString str2;
    2. str2="c:\nnimagen.bmp";
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. QString str2;
    2. str2="c:\\nnimagen.bmp";
    To copy to clipboard, switch view to plain text mode 

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

    Thanks
    Last edited by jokinb; 22nd October 2010 at 17:02.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with a dynamicCall and a Qstring variable

    one of the questions is resolved
    What was the other question?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Oct 2010
    Posts
    7
    Qt products
    Qt4

    Default Re: Problem with a dynamicCall and a Qstring variable

    So it is supossed that the QInputDialog::getText method do this conversion internally?

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with a dynamicCall and a Qstring variable

    No.
    Why should it?
    QInputDialog is just a convenience class for simple input.
    It knows nothing about paths.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Problem calling a routine with dynamicCall
    By franco.amato in forum Qt Programming
    Replies: 10
    Last Post: 10th May 2010, 17:59
  2. dynamicCall and QByteArray - strange characters
    By franco.amato in forum Qt Programming
    Replies: 120
    Last Post: 28th April 2010, 21:11
  3. Replies: 0
    Last Post: 16th April 2010, 23:21
  4. Variable table name problem
    By waynew in forum Qt Programming
    Replies: 4
    Last Post: 12th March 2010, 01:41
  5. Replies: 1
    Last Post: 28th May 2008, 16:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.