Results 1 to 4 of 4

Thread: library :: QString to LPSTR

  1. #1
    Join Date
    Oct 2009
    Location
    Brazil Maceió/Alagoas
    Posts
    24
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Question library :: QString to LPSTR

    Hello everyone,
    I'm loading a library in "C" and its functions require parameters of type LPSTR.
    Do you have any way to convert QString to LPSTR?

    Grateful.
    Last edited by josecarlosmissias; 24th November 2009 at 15:21.

  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: library :: QString to LPSTR

    Look at the the LPSTR difintion, and you will see its typedef CHAR*...
    ==========================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 2009
    Location
    Brazil Maceió/Alagoas
    Posts
    24
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: library :: QString to LPSTR

    Quote Originally Posted by high_flyer View Post
    Look at the the LPSTR difintion, and you will see its typedef CHAR*...
    right, how do I convert QString to char *, eg:
    //--------------------
    typedef int (* CaptTxtDllECF) (int type, char * faixai, faixaf char *, char * path, int show char * str);

    ....
    //------------------
    QString pathToSave = "c:\\tmp\\lx.txt";
    status = captTxtDllECF (_LX, "", "", path, 1, "serial");

    error:

    C: / workspace / captureW /. / Main.cpp: 227: error: 'int (int, char *, char *, char *, int, char *)': can not convert parameter 4 from 'QString' to 'char * '

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: library :: QString to LPSTR

    Well, QString has a toLocal8Bit method, and QByteArray has a method constData to return a const char *. Or you use Data instead to remove the const'ness. Its better to use the former unless you need to modify the string however.

  5. The following user says thank you to squidge for this useful post:

    josecarlosmissias (24th November 2009)

Similar Threads

  1. Extending a plugin in a static library
    By ultim8 in forum Qt Programming
    Replies: 5
    Last Post: 25th March 2010, 15:10
  2. Qy 4.4.3 MySQL driver failed
    By pamalite in forum Installation and Deployment
    Replies: 2
    Last Post: 23rd January 2010, 01:09
  3. File rename detection
    By bunjee in forum Qt Programming
    Replies: 6
    Last Post: 23rd July 2009, 15:22
  4. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 16:26
  5. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59

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.