ProjectHax

ProjectHax General Programming

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 05-13-2011
WeeMan WeeMan is offline
Administrator
 
Join Date: Apr 2011
Location: United States
Posts: 12,358
Default Beginners Guide to QString's

Here's a quick guide on how to use QString's. They are pretty simple to use.

1. Simple strings
Code:
QString test("test");
The string variable 'test' now has the value of 'test'.

2. Arguments
Code:
QString test(QString("arg1: %0 arg2: %1").arg(1).arg(2));
You can append more arguments by tacking on an extra '.arg()'

3. Converting from a QString
You can convert a QString to an STL string or even to a char array. QString's work almost exactly like STL string except they are used in Qt classes instead of STL strings. They even have similar functions like clear() and append().
Code:
QString test1("test");

std::string test2 = test1.toStdString();

char test3[32] = {0};
sprintf_s<32>(test3, test1.toStdString().c_str());
4. Converting to a QString
It's even easier to set the data of a QString.
Code:
char test1[] = "test";
std::string test2 = "test";

QString test3(test1);
QString test4(test2.c_str());
__________________
New forum coming soon!
https://forum.projecthax.com/t/welcome/37
  #2  
Old 05-24-2011
WeeMan WeeMan is offline
Administrator
 
Join Date: Apr 2011
Location: United States
Posts: 12,358
Default

If you have problems with toStdString() you can use toLatin1().data() instead which will give you a const char* array instead of an STL string.
__________________
New forum coming soon!
https://forum.projecthax.com/t/welcome/37
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:12 PM.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.

Google+ Facebook Twitter