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. Manipulate QInputDialog::SetText as a String
Qt 6.11 is out! See what's new in the release blog

Manipulate QInputDialog::SetText as a String

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.1k 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.
  • L Offline
    L Offline
    leoamz
    wrote on last edited by
    #1

    Hi,

    I have a problem with my code, I want the user to input a text that I can use as a QString, ( that can handle \n )

    When I do QString x = "Test\n blabla\n testest" and I do x.toStdString(); it works and handle the \n
    On the other hand, when the user input : "Test\n blabla\n testest" and I convert it to a stdString, it doesn't handle the \n and it just print it as if \n were normal words.

    For exemple it works when I initialize the code as "qsj" is but if I enter the same thing in my QInputDialog thing it doesn't work even if "zz" is a QString too.

    aaa.PNG

    I really don't understand I tried to convert it to everything it still doesn't work if someone could help me it would be highly appreciated, thank you !

    jsulmJ 2 Replies Last reply
    0
    • L leoamz

      Hi,

      I have a problem with my code, I want the user to input a text that I can use as a QString, ( that can handle \n )

      When I do QString x = "Test\n blabla\n testest" and I do x.toStdString(); it works and handle the \n
      On the other hand, when the user input : "Test\n blabla\n testest" and I convert it to a stdString, it doesn't handle the \n and it just print it as if \n were normal words.

      For exemple it works when I initialize the code as "qsj" is but if I enter the same thing in my QInputDialog thing it doesn't work even if "zz" is a QString too.

      aaa.PNG

      I really don't understand I tried to convert it to everything it still doesn't work if someone could help me it would be highly appreciated, thank you !

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @leoamz said in Manipulate QInputDialog::SetText as a String:

      "Test\n blabla\n testest" and I convert it to a stdString, it doesn't handle the \n and it just print it as if \n were normal words.

      This can't work. \n is only handled in code as special charecter. If user inputs it as string in a widget it will be just a string "\n". If you want user to enter new line then the user has to press Enter key.

      And why would you ask user to enter "\n" instead of pressing Enter key? Normal users usually have no idea that "\n" is special character in a programming language...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • L Offline
        L Offline
        leoamz
        wrote on last edited by
        #3

        It's not for normal users I created a code using Bison and Flex where I created my own language that plot mathematical function that's why I really need to use the \n.

        There is no way to input a text in a window that can work as if you initialize a QString variable ?

        1 Reply Last reply
        0
        • L leoamz

          Hi,

          I have a problem with my code, I want the user to input a text that I can use as a QString, ( that can handle \n )

          When I do QString x = "Test\n blabla\n testest" and I do x.toStdString(); it works and handle the \n
          On the other hand, when the user input : "Test\n blabla\n testest" and I convert it to a stdString, it doesn't handle the \n and it just print it as if \n were normal words.

          For exemple it works when I initialize the code as "qsj" is but if I enter the same thing in my QInputDialog thing it doesn't work even if "zz" is a QString too.

          aaa.PNG

          I really don't understand I tried to convert it to everything it still doesn't work if someone could help me it would be highly appreciated, thank you !

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @leoamz If you want your users to enter \n then you will need to replace "\n" string with new-lines:

          str.replace("\\n", "\n");
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          L 1 Reply Last reply
          1
          • jsulmJ jsulm

            @leoamz If you want your users to enter \n then you will need to replace "\n" string with new-lines:

            str.replace("\\n", "\n");
            
            L Offline
            L Offline
            leoamz
            wrote on last edited by
            #5

            @jsulm God thank you it's working i know it was a real weird question, you saved me thanks !

            1 Reply Last reply
            1

            • Login

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