Results 1 to 5 of 5

Thread: QString -> char*

  1. #1
    Join Date
    Feb 2007
    Posts
    29
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default QString -> char*

    I understand how important internationalization is etc. But I really need some way to convert the QString returned by getOpenFileName to a char* so I can call this function from this library I'm using.

    I'm guessing that the way I'm converting the string is incorrect because the "not a map" about box triggers. However I don't know of any function that will echo back a char* C style string to me.

    I tried including windows.h and saying: MessageBox(NULL, "A NORMAL STRING DAMINT", "MESSAGE", MB_OK); the way I used to do things when I coded in C. But I get "cannot convert const char* to const WCHAR*"

    What the hell is a WCHAR???

    Qt Code:
    1. void MainWindow::open() {
    2. MPQHANDLE *MPQarchive;
    3.  
    4. QString FileString = QFileDialog::getOpenFileName(this, tr("Open File"), "/",
    5. tr("Starcraft maps (*.scm *.scx *.chk);;All Files (*.*)"));
    6. if(FileString.endsWith(".scm") || FileString.endsWith(".scx")) {
    7. if(!SFileOpenArchive((char*)FileString.data(), 1, 0, MPQarchive)) {
    8. QMessageBox::about(this, tr("Not a map?"), FileString);
    9. }
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

  3. The following user says thank you to jpn for this useful post:

    scwizard (21st February 2007)

  4. #3
    Join Date
    Feb 2007
    Posts
    29
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QString -> char*

    Thanks, stuff works now.

    But out of curiosity is there a way to echo back a char* using some kind of messagebox?

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QString -> char*

    Quote Originally Posted by scwizard View Post
    But out of curiosity is there a way to echo back a char* using some kind of messagebox?
    Qt Code:
    1. const char *string = "xxxxxxxxxxxxxxxx";
    2. QMessageBox::information(0, "title", string);
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QString -> char*

    Quote Originally Posted by scwizard View Post
    I tried including windows.h and saying: MessageBox(NULL, "A NORMAL STRING DAMINT", "MESSAGE", MB_OK); the way I used to do things when I coded in C. But I get "cannot convert const char* to const WCHAR*"

    What the hell is a WCHAR???
    WCHAR is a wide character used in Unicode strings. Qt uses Unicode internally, so if you include any windows' header, it will also have Unicode support turned on.

    Try:
    Qt Code:
    1. MessageBox(NULL, _T("A NORMAL STRING DAMINT"), _T("MESSAGE"), MB_OK);
    To copy to clipboard, switch view to plain text mode 
    (you might need to include tchar.h or something similar).

Similar Threads

  1. QString problem
    By vermarajeev in forum Qt Programming
    Replies: 9
    Last Post: 26th October 2006, 19:10
  2. Replies: 2
    Last Post: 12th October 2006, 09:17
  3. QSqlQueryModel + set Write
    By raphaelf in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2006, 08:55
  4. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 14:52
  5. QProcess in a QThread
    By chombium in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2006, 15: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.