Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Convert std::string to QLineEdit

Convert std::string to QLineEdit

Scheduled Pinned Locked Moved General and Desktop
qlineeditstdstringconvert
4 Posts 2 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gshannon154
    wrote on 2 Apr 2015, 17:00 last edited by
    #1

    Hi all,

    So I have a situation...

    The following code allows me to set the text in a QLineEdit called cores using a map called parameterMap:

    "advancedsettings->getUi()->cores->setText(QString::fromStdString(parameterMap["cores"]));"

    I have a list called allParameters, the entries of which are identical to the keys of parameterMap and the QLineEdit's in advancedsettings. I would like to iterate over allParameters to change the text in every QLineEdit in advancedsettings like so:

    "for(list<string>::iterator it = allParameters.begin(); it != allParameters.end(); ++it){
    advancedsettings->getUi()->*it->setText(QString::fromStdString(parameterMap[*it]));
    }"

    However, the above code produces:
    error: 'struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >' has no member named 'setText'

    and:

    "string myString = "cores";
    advancedsettings->getUi()->myString->setText(QString::fromStdString(parameterMap[myString]));
    "

    results in:
    'class Ui::AdvancedSettings' has no member named 'myString'

    How can I achieve what I want to? I must need to convert a std::string to some QT data type but none of my attempts have worked.

    Many thanks,

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 2 Apr 2015, 17:21 last edited by
      #2

      Hi and welcome to devnet,

      lineEdit->setText(QString::fromStdString(yourStdString));
      

      Is the correct form.

      Do you have as much QLineEdit in your UI to enter all the strings from your parameterMap ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gshannon154
        wrote on 8 Apr 2015, 07:28 last edited by
        #3

        Hi!

        Many thanks for your help.

        To answer your question I have more strings in parameterMap than QLineEdit's in the UI (advancedsettings).

        I'd like to iterate through all the QLineEdit's in advancedsettings rather than manually having to do something like:

        advancedsettings->getUi()->firstQLineEditInadvancedsettings->setText(QString::fromStdString(myStdString))

        advancedsettings->getUi()->secondQLineEditInadvancedsettings->setText(QString::fromStdString(myStdString))

        ...

        advancedsettings->getUi()->lastQLineEditInadvancedsettings->setText(QString::fromStdString(myStdString))

        Is there a way I can achieve this?

        Man thanks,

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 8 Apr 2015, 23:09 last edited by
          #4

          You can create the QLineEdits dynamically

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          4/4

          8 Apr 2015, 23:09

          • Login

          • Login or register to search.
          4 out of 4
          • First post
            4/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved