Save QString in QSettings without quotes - qt

I save some values in my .ini-file which works fine.
Now I want to save a QString in the file, which I put together inside my application.
QString s = "xwr289vjkloji9";
QSettings settings("file.ini", QSettings::Format::IniFormat);
settings.setValue("dbp", s);
Inside my file.ini it saves dbp="xwr289vjkloji9"
Basically this is right, but I need the String without quotation marks. Is there any way to remove them or should I save the String differently?
I cannot cut the first and last letter, because the quotes do not exists inside the String, they're just the String-identifier.
My only option now is to cut the quotation marks when receiving the value back from the file but I want to try it without, maybe there is a way.

Related

How to display the content of an ELF file in QTextEdit?

I need to display all the bytes from and ELF file to a QTextEdit and i did not find any reasonable way to do this. I could print maximum "?ELF??" then nothing. The content of the ELF is read in a char* array (this is a requirement, can't change that) and yes, for sure the content is read.
I am guessing that your code looks something like this:
char *elf = ReadElfFile();
QString str(elf); // Constructs a string initialized with the 8-bit string str.
QTextEdit edit(str);
The problem is that QString constructor will stop on first NUL character, and the ELF file is full of them.
If you want to make a QString that contains NULs, do something like this:
QString str(QByteArray(elf, length_of_elf));
This just nearly broke me too, so I'll post my solution to anyone interested.
Let's say I have a QByteArray data that is filled like so
data += file.readAll();
I'll then invoke an update of the QTextEdit where I'll do
QByteArray copy = data;
QString text = copy.replace((char)0x00, "\\0");
textEdit.setPlainText(text);
This way, all null bytes in the data will be displayed as the printable string \0.
Since I want changes of the textEdit to be reflected in my data, I have to parse this back using
QByteArray hex = textEdit.toPlainText().toUtf8().toHex().toUpper();
hex.replace("5C30", "00");
hex.replace("5C00", "5C30"); // oops, was escaped
data = QByteArray::fromHex(hex);
I'm using the hex format because I just could not get the replace to work with null byte characters. The code above first replaces all occurrences of the string \0 with null bytes in the data. Then it replaces any \ followed by a null byte back with \0 - which essentially means \\0 becomes \0.
It's not very elegant, but maybe it helps anyone ending up here to move on in the right direction. If you have improvements, please comment.

How do I concatenate strings in arduino?

sorry I am a bit rusty here, how do I concatenate these 2 outputs?
display.println(timeinfo->tm_hour);
display.println(timeinfo->tm_min);
If you just want them to appear in the output one after another on the same line then use print instead of println for the first one. Println adds a newline to the end of the output and print doesn't. It's always good to look stuff like that up before using a function.
If you really want them put together into one string then you will have to show where those strings are coming from. If they are String class objects you can just use + to put them together. If they are proper c-style strings then you will need to use strcat.
How are defining them?
If you have initialized as arrays of characters:
Example: char exampleCString[50] = "This is a C string";
Then you can use strcat() function in C:
strcat(str1,str2);
Note: Make sure "str1" buffer is big enough, because the result goes there.
If on the other hand, you have initialized your strings as objects of String class:
Example: String exampleJavaString="This is a Java String example"
Then just use the + operator to add them:
str1=str1+str2:

QDesktopServices truncates the # sign in a path

If I have a # sign in my path, QDesktopServices truncates the string resulting in everything behind and including this sign beeing removed. Using the approach below results in inserting a %23 sign which also fails opening the file. I want that the string is copied into the address field as I defined (with a #).
QString file = "F:/the_path/to_the_/generated#_html_file.html";
QUrl test = QUrl::fromLocalFile(file);
// gives url="file:///F:/the_path/to_the_/generated%23_html_file.html";
QDesktopServices::openUrl(test); //unable to open

R: Handling strings with a single or odd number of quotation marks

Consider the following string:
"><script>alert(1);</script>
I wish to assign this string (or a string like it) to an R variable.
If I try to do this the traditional way, such as:
x <- as.character("><script>alert(1);</script>)
the command fails due to the presence of the single quotation mark within the string itself. Is there a method to get round this complication without manipulating the string entirely?
It is important to keep the integrity of the string intact. For example, a method to get round this problem would be to change the quotation mark to an apostrophe, or to delete the quotation mark; but this is unacceptable.
Cheers

Does QString::fromUtf8 automatically reverse a Hebrew string?

I am having a problem where a Hebrew string is being displayed in reverse. I use QTableWidget to display some info, and here the string appears correctly using:
CString hebrewStr; hebrewStr.ToUTF8();
QString s = QString::fromUtf8( hebrewStr );
In another part of my program this same string is displayed on the screen, but not using QT, and this is what is being shown in reverse:
CString hebrewStr;
hebrewStr.ToUTF8();
I have debugged and hebrewStr.ToUTF8() in both cases produces the exact same unicode string, but the string is only displayed correctly in the QTableWidget. So I am wondering if Qt automatically reverses a given Hebrew string (since it is a rigth-to-left language). Thanks!
Yes, in this case QString generate the full unicode wchar_t from the UTF-8 encoded string. If you would like to do similar thing in MFC, you should use CStringW and decode the string.
Use MultiByteToWideChar for UTF8 to CStringW conversion.
Connected question in StackOverflow.

Resources