Important: Please read the Qt Code of Conduct -


  • How can i show part of a string by QString?for example
    in c we do it like that,-----------
    @int length = 5;
    printf("%*.*s", length, length, "hello there");

  • Are you looking for QString::mid()?

  • thank you very much for the reply.
    i want to publish my message in plainTextEdit->appendPlainText(Qstring(a.c_str()))---------suppose my string is"1234567890",i want to show only the last 4 digit or middle can i do that?

  • Did you try reading the documentation of [[doc:QString]]?

  • its a large document to read.i am trying but need lots of passion.but your note helped i found.thanks

  • @std::stringstream ss1;

    uint32 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,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;

        std::stringstream ss,ss1;
        std::string b=ss1.str();
        QString a(QString::fromStdString(b));
        ss << "hello world.\trequest number=["<<m_icounter<<"]";
        msg.data_1 = ss.str();
        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": 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) };


    plainTextEdit->appendPlainText(QString("Time during send = %1 -> Message:: %2")
    Brain to terminal. Not tested. Exemplary.

Log in to reply