[Qt-interest] how to convert QMap<QString, QString>::const_iterator to QString?
Ross Driedger
ross at earz.ca
Mon Apr 5 19:36:39 CEST 2010
Please reply to the list only. Thanks.
On 5-Apr-10, at 11:17 AM, Werner Van Belle wrote:
> Ross Driedger wrote:
>> On 5-Apr-10, at 6:49 AM, qt-interest-request at trolltech.com
>> <mailto:qt-interest-request at trolltech.com> wrote:
>>> QMap<QString,QString> args
>>> QMap<QString,QString>::const_iterator i = args.constBegin();
>>> while (i != args.constEnd()) {
>>> //cout << i.key() << ": " << i.value() << endl;
>>> QString temp(i.key().toStdString() + ": " +
>>> i.value().toStdString()); // this dosn't work !!!
>>
>> Why would you convert a QString to std::string object and then back
>> to
>> QString?
> I could utter a couple of guesses:
>
> a- You have two libraries: one using strings the other QStrings. You
> need to pass data from one to the other and back.
> b- You have a large chunk of code you wrote yourself and you don't
> _want_ to modify everything you wrote to fit with QStrings. Instead,
> you
> want the user interface in its own module and you want to keep it
> there.
> For instance, you also have a GTK UI.
These two use-cases are not what is shown in the example. I am
perfectly aware and capable of separating 'pure' c++ code with Qt code
-- I do it regularly in my programming. The OP is converting back and
forth within the same function call which is neither of your two use-
cases.
>
>> QString is perfectly capable of doing the job itself, so there is no
> reason to switch from one to the other and back.
>
> I'm sure it is, but honoustly. The argument: 'why don't you use
> QString'
> is not really answering the question,
That is because the question is, frankly, very poorly asked because
there is no context. "It doesn't work. Why not?", does not explain
what the OP expected as a result and what (s)he observed. Perhaps,
with my 'non-answer', the OP will craft future questions with a bit
more care.
...and as far as how to accomplish what I think the OP wants to
accomplish, I suspect the answer is available through a simple
application of RTFM; the Qt's docs, good C++ reference or a Google
search will probably be faster than posting to the list. Think of it
as 'tough-love'.
Ross Driedger
ross (at) earz (dot) ca
More information about the Qt-interest-old
mailing list