Unsolved Manipulate QInputDialog::SetText as a String
-
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.
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 !
-
@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...
-
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 ?
-
@leoamz If you want your users to enter \n then you will need to replace "\n" string with new-lines:
str.replace("\\n", "\n");
-
@jsulm God thank you it's working i know it was a real weird question, you saved me thanks !