Skip to content
QtWS25 Call for Papers
  • 0 Votes
    3 Posts
    184 Views
    magrifM

    Thanks, I found examples for JS here.

  • 0 Votes
    2 Posts
    347 Views
    JonBJ

    @RuWex

    Iterate along the characters in the string till you find a digit; or QString::indexOf(QRegularExpression("m[0-9]")) probably does this.

    The last character before the digit is the index minus 1.

  • 0 Votes
    3 Posts
    298 Views
    JonBJ

    @jsulm
    OoI, why did Qt6 QString feel the need to introduce sliced() when we have had mid() for years?
    EDIT Oh, mid() docs now say

    If you know that position and n cannot be out of bounds, use sliced() instead in new code, because it is faster.

  • Why cling onto RegEx?

    Moved The Lounge
    13
    0 Votes
    13 Posts
    986 Views
    B

    @candy76041820 said in Why cling onto RegEx?:

    1a. Well it's just a makeshift & demonstrative snippet to convey my idea of usting something instead of regex, so don't be so picky.

    Your point was to demonstrate that a simpler solution was available. However, if you can't demonstrate that the simpler solution does everything required then it isn't a solution and you haven't demonstrated anything. It's hardly being "picky" to point this out!

  • 1 Votes
    3 Posts
    507 Views
    johngodJ

    I use

    qsTr(" sopdk apdapo dapodk aspod ad\n" + "ssdkopaksdopakdp ksopdak opdad\n" + "aiojdaios daoisd jaoidu aoidi adoia dj" )

    Let me know if someone uses other solutions

  • 0 Votes
    3 Posts
    276 Views
    J

    right ! my mistake !thanks

  • 0 Votes
    11 Posts
    5k Views
    J.HilkJ

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

  • 0 Votes
    3 Posts
    335 Views
    L

    @mrjj

    Thanks I tried the resource system and it works.

    QFile file(":/python_scripts/script1.py"); file.open(QIODevice::ReadOnly | QIODevice::Text); QString pythonScript = file.readAll();
  • 0 Votes
    5 Posts
    9k 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
    4 Posts
    1k Views
    Christian EhrlicherC

    You already use QTextStream::readLine() - so why do you read it with ifstream before? You simply read it twice for no reason.

  • 0 Votes
    16 Posts
    4k Views
    W

    If you guys are still interested in the topic. See https://github.com/chalkwu/control-system.
    I think it is a basic DIY solution. Cheers.

  • 0 Votes
    2 Posts
    2k Views
    JKSHJ

    @GhostWolf said in 2's complement convertion:

    uint32_t test2 = (unit.value(1)<<16) | unit.value(0);

    Just store the result as a signed integer (int32_t) instead of unsigned (uint32_t).

    You don't need to change the bit pattern (0b11111111_11111111_11111111_11111111).

    Interpreting this pattern as Unsigned gives you ‭4294967295 Interpreting this pattern as Signed gives you -1.
  • 0 Votes
    6 Posts
    4k Views
    J.HilkJ

    @Geeva
    The easies way is to move your task into its own function that expects q QList<QString> as an argument:

    void myClass::myFunction(QList<QString> startvalue){ //do stuff eg: qDebug() << "Value Received from server :" << startvalue; QStringList first = startvalue.split("|"); int firstSize = first.size(); qDebug() << "size :" << firstSize; if(firstSize == 5){ first1 = first[2]; first2 = first[3]; }..........(continue) }

    then you call that function for each and every item in your QList<QList<QString>>

    QList<QList<QString> > myList for(QList<QString> ls : myList){ myFunction(ls); }
  • 0 Votes
    9 Posts
    3k Views
    AmoghA

    you can send the string to other class by simply placing it in the Signal, and catch the signal at the other class.

  • 0 Votes
    5 Posts
    13k Views
    E

    @Wieland Thanks for the reference - that has worked for me.

    Also, thanks for the Qbs information - i hadn't seen this before but will look into it

    @SGaist - thanks for the info

    I had previously tried something similar but I think it may have been the escaping of quotes which caught me out.

  • 0 Votes
    2 Posts
    1k Views
    SGaistS

    Hi,

    As silly as it may sound but wouldn't removing << std::endl from the checking line be enough ?

  • 0 Votes
    11 Posts
    15k Views
    jsulmJ

    @Mandar-Khire If you change your basic C++ program like this then you will not see the output as well:

    #include <iostream> using namespace std; int main() { cout << "Hello World by C++!"; while(true); return 0; }

    Qt uses an event loop, so after executing

    void Widget::on_showButton_clicked() { cout << "Hello World by QT!"; }

    your program is "sleeping" in the event loop and not flashing cout buffer.

  • 0 Votes
    5 Posts
    22k Views
    Ni.SumiN

    Hi @Wieland ,

    I did not test the code. But Yes, you are right. I tested @Punit 's code after my comment. It worked for me too(missed only that semicolon).

  • 0 Votes
    5 Posts
    3k Views
    M

    @JKSH Thanks.
    By using of RegExp, the problem is solved.
    For other users who read this question:
    My main string is a string of hex (without any space or \x or 0x). I replcae ? in substring by [0-9a-f] and use Qt::CaseInsensitive option:

    regex.replace("?","[0-9a-f]"); index = mainString.indexOf(QRegExp(regex,Qt::CaseInsensitive));
  • 0 Votes
    4 Posts
    3k Views
    Arty.McLabinA

    @Chris-Kawa said:

    t by value creates copies and is extremely bad for locality. Passing pointers is optimizer unfriendly. Always prefer a const referenc

    thanks for the advices! i will start working on it.