QString
-
@std::stringstream ss1;
uint32 stamp_1;
ss1<stamp_1;
QString a=ss1.str();
@
i am not understanding what is the wrong in my code?i am getting this kind of error:
conversion from ‘std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ to non-scalar type ‘QString’ requested
-
i got the answer.
QString QString::fromStdString ( const std::string & str ) [static]
Returns a copy of the str string. The given string is converted to Unicode using the fromAscii() function.This constructor is only available if Qt is configured with STL compatibility enabled.
-
I am really lost on to what you are trying to achieve. You don't need the std stuff to work with streams and strings, and not usign it would make your code more readable I think. Perhaps you should tell us what you want to achieve, rather than just showing us the concrete steps you are taking. The bigger picture is missing here.
Also: please put code sections between @ tags. That makes them much easier to read.
-
I have designed a GUI Window for my project.The Gui window consist of two push button and one plain text edit.so,when i press a push button it will show the output in the plain text edit and i also using QTimer for continuous process.
In my project I used a time Stamp which will show the system time and uint32 primitive type.And this time i have to put in the plain text edit using QString.for this reason i have to convert my uint32 into string type.So,what i did,is that,I first convert the uint32 into streamstring then to string and finally i used
QString::fromStdString ( const std::string & str ) to make it suitable for QString.If you have any easy solution,please share.
my section of code is here:
@ First_Gui_Task::Num msg;
msg.stamp_1=ros::Time::now();std::stringstream ss,ss1; ss1<<msg.stamp_1; std::string b=ss1.str(); QString a(QString::fromStdString(b)); ss << "hello world.\trequest number=["<<m_icounter<<"]"; msg.data_1 = ss.str(); m_request_pub.publish(msg); plainTextEdit->appendPlainText(QString("Time during send = ") % QString(a.mid(5,11)) % QString("->Massage:: ") % QString(msg.data_1.c_str())); @
-
Hello.
[quote author="Andre" date="1348485098"]Did you try reading the documentation of [[doc:QString]]?[/quote]???
If you want to make a string from a number just use some of QString's "number":http://qt-project.org/doc/qt-4.8/qstring.html#number methods -
[quote author="muin028" date="1348569443"]If you have any easy solution, please share ...[/quote]
Either use Qt, or the standard library, but don't use both.
@
struct Num
{
QTime stamp_1;
QString data_1;
}:First_Gui_Task::Num msg = { QTime::currentTime(),
QString("hello world.\trequest number=[%1]").arg(m_icounter) };m_request_pub.publish(msg);
plainTextEdit->appendPlainText(QString("Time during send = %1 -> Message:: %2")
.arg(msg.stamp_1.toString(Qt::ISODate))
.arg(msg.data_1));
@
Brain to terminal. Not tested. Exemplary.