Skip to content
  • 0 Votes
    6 Posts
    299 Views
    MohammadsmM

    @jsulm
    I tried QChar to convert unicode and my problem solved. now qDebug prints the text correctly. 👌🏻
    I also copied the readAllStandardOutput() to a QString and removed backslashes via remove("\x5C\x75").

  • 0 Votes
    13 Posts
    589 Views
    SGaistS

    That was a nasty one. Glad you found out and thanks for sharing !

  • 0 Votes
    3 Posts
    343 Views
    JonBJ

    @Basile_Starynkevitch
    I don't know what your command is or how you are presently sending it to QProcess as you do not show these.

    You can normally leave the correct quoting to QProcess with an argument list. If, for some reason, you have a string and want to split it into arguments for QProcess you can use QStringList QProcess::splitCommand(QStringView command). Also void QProcess::startCommand(const QString &command, QIODeviceBase::OpenMode mode = ReadWrite) presumably uses that internally.

    Note however that you reference https://docs.gtk.org/glib/func.shell_quote.html and that says

    Quotes a string so that the shell (/bin/sh) will interpret the quoted string to mean unquoted_string.

    Quoting to a shell like /bin/sh can have its own rules. For example, echo '$HOME' and echo "$HOME" behave differently. I don't know how/whether you deal with that. And your GLib shell_quote ignores this.

  • 0 Votes
    20 Posts
    1k Views
    JonBJ

    @swankster
    :) Like I said, just build the (correct, including whatever quoting, and if you are OK on possible SQL injection attacks!) string and pass that without using binding, for this query.

  • 0 Votes
    6 Posts
    1k Views
    JonBJ

    @CJha
    That is great. I might be forgetting, but I don't think ~ or # are actually regular expression special characters. However, the escape() method may replace every punctuation character with \-character (including non-ASCII characters like copyright) because that never does any harm/is allowed on any punctuation character. Or it might be enough to let * go to \* and then revert any \*s to plain *s (actually .* in your case).

  • 0 Votes
    3 Posts
    485 Views
    S

    @Chris-Kawa Thanks for the quick reply! It might be helpful, I will think whether I can use it to my advantage.

  • 0 Votes
    6 Posts
    1k Views
    L

    @ChrisW67 thank you.

  • 0 Votes
    23 Posts
    3k Views
    Kent-DorfmanK

    @JonB said in converting from float or double to QString results in output being 0:

    Warning: The QString content may only contain valid numerical characters which includes the plus/minus sign, the character e used in scientific notation, and the decimal point. Including the unit or additional characters leads to a conversion error.

    In which case RTFM is the rule of the day! but I'm lazy.

  • 0 Votes
    10 Posts
    804 Views
    Chris KawaC

    Btw. to put my money where my mouth is this is my proposal for this problem. Yes, I'm assuming the format is fixed and search operations won't return -1. If that isn't the case you can add one if to range check the indices.

    std::ranges::sort(vec, [](QStringView a, QStringView b) { int pos_a = a.lastIndexOf(' '); int pos_b = b.lastIndexOf(' '); int int_a = a.sliced(pos_a).toInt(); int int_b = b.sliced(pos_b).toInt(); return int_a < int_b; });

    Do you consider this unreadable? And no, this is not fully optimized either, because it does the same int conversions multiple times, but I consider something like this to be a "good enough starting point" and in-depth optimization is possible if need arises e.g. by caching the conversions or changing the data structure.

    EDIT Just after posting I realized you can do the QStringView creation right in the params, so even simpler.

  • 0 Votes
    3 Posts
    697 Views
    2

    Thanks for the reply @SGaist. What I wanted was to update some data (in form of text) from python backend, most of the tutorials I saw were based on using signals and slots. were as I only needed a slot to read without any triggering signal. Though I've been able to finally figure it out and spending this much time actually made me understood it more. I used QTimer to refresh the backend function every half a second.

  • 0 Votes
    13 Posts
    8k Views
    C

    @Sina-Ranjkesh-zade said in Converting QByteArray to QString:

    For "standard input" if you mean input arguments of the process, I got this error:

    No, I meant standard input. That is , the python program reads from a terminal and accepts input just as if you typed it (except it is the Qt program sending that input). The Qt program can send a command to the python program, send the data it needs, and read the result (if there is one) back on the python program's standard output. Or you can used shared memory, or a socket, or files, or do whatever the python program is doing in the Qt program...

  • 0 Votes
    5 Posts
    784 Views
    R

    @JKSH Oh wow, you're completely right. I didn't know qDebug() behaved like this, I assumed noquote() was the default. Thanks for the help, I don't know how long it would have taken me to find out.

  • 0 Votes
    11 Posts
    6k Views
    J.HilkJ

    @JKSH
    I'll leave that here...
    856158c1-5380-4d6f-8a1c-344983719657-image.png

  • 0 Votes
    3 Posts
    548 Views
    A

    @JonB thanks!

  • 0 Votes
    2 Posts
    900 Views
    SGaistS

    Hi,

    One possible way is to use QRegularExpression::match or since it looks like xml, you can use QXmlStreamReader.

  • 0 Votes
    12 Posts
    5k Views
    SGaistS

    @JonB tests are in order ! It would indeed be simpler.

    As I miswrote (and fixed) it's possibly a memory issu :-).

  • 0 Votes
    2 Posts
    468 Views
    J

    Now I realized I have to set QDataStream::setVersion to QDataStream::Qt_4_7. I think the problem is solved.

  • 0 Votes
    5 Posts
    11k Views
    Linus JahnL

    Thanks for your replies.

    It probably doesn't matter at all, because the only result will be that the library is a few micro seconds faster at runtime / at load time.

    The reason is probably rather a psychological one than a real performance issue. -- I'd like to write clean code, use the ideal way and don't want to see warnings when running i.e. clazy on my code. When looking at performance there are probably other issues that have a greater impact on the performance.

    I actually tested it now:

    Test 1: Runtime usage #include <QString> const char *xmlns = "urn:ietf:xml:ns:xmpp-sasl"; // OR: const QString xmlns = QStringLiteral("urn:ietf:xml:ns:xmpp-sasl"); int main() { for (int i = 0; i < 1e9; i++) { // Option A: QString text(xmlns); // Option B: appending 'a' QString xmlnsPlusA = QString(xmlns) + 'a'; } } QStringLiteral char* A: QString( ), QStringLiteral is implicitly-shared 0.5 s 52 s B: appending 'a' 27 s 91 s

    -> The relative difference is high, but the absolute numbers are not relevant: You need to convert about 500 kB (about 20k comparable strings), so that this takes more than 1 ms and gets a performance problem in a GUI application.

    Test 2: Start-up time

    I also created a test binary with 10k global static constants (all with the same content):

    QString (cast from char *) QStringLiteral char * compile time 3 s 3.5 min < 1 s binary size (stripped) 410 kB 1270 kB 320 kB time to run (10k times) 33 s 23 s 19 s

    I guess the QStringLiteral binary takes longer to run, because it is larger and only partially, because of the non-POD CTORs.

    -> Using QStringLiteral has a slightly larger impact on the execution time than I've expected, but this is still not relevant since you usually have less than 10k global static strings and you only load the binary once instead of 10000 times. As long as you're not developing for an arduino this has probably no relevance.

    As expected the usage of QStringLiteral makes the binary a bit larger, the start-up time a little little bit larger, but is faster compared to casting from ascii everytime at runtime.

    I'll see if I can do anything with QArrayData, not because it's important, just for fun.

  • 0 Votes
    9 Posts
    4k Views
    aha_1980A

    @emp1953 said in How to remove quotes and eol characters from QString?:

    There is still the annoying little "square" shape after every item in the QListWidget.

    QFile::readLine() behaves different on Windows and Linux, your can read that in the docu.

    On Linux it assumes \n line endings, on Windows \r\n ones, which it replaces with \n.

    Your file is none of these, it has mixed endings. If you want to use it in Linux, you have to normalize the line endings first. Otherwise readLine() will not do what you expect and every following procedure will fail.

    The square bracket you see is probably the \r char, which cannot be displayed otherwise.

    From within the Qt Creator development environment it does in fact compile without warnings and outputs an executable.

    But not the code you posted above. This code is invalid and no compiler will accept it. Double check what you are doing.

    Regards