Skip to content
  • 0 Votes
    9 Posts
    240 Views
    G

    @JonB @ChrisW67 Thanks! I'll use a QScopedPointer!

  • 0 Votes
    3 Posts
    177 Views
    J

    @JonB thank you

  • QTimer is very inaccurate

    Unsolved Qt for MCUs
    31
    0 Votes
    31 Posts
    3k Views
    P

    @jsulm, @JonB
    Hello Both,

    I found the reason for high CPU load.

    Background:
    We have our own devices and I'm working on creating user Interfaces on the display of our device. We have many qml files to create some objects which needs to displayed on the device.

    We have a Software Tool which draws the objects on the PC using qml Files as per the user settings(like the size, position of the object on the display etc..). Then the objects are downloaded into our device.

    Root cause for High Cpu Load, Inaccuracy of QTimer:
    As a part of the objects that are created and downloaded from PC to the device, there is a ".gif(AnimatedImage)" object also.
    We are setting the "playing" property of this qml object to "true". So, this object is causing high CPU load even though the page in which this object is present is made invisible(i.e "visible" property is changed to false). This is the reason also for the inaccuracy of the QTimer as AnimatedImage is consuming lot of CPU time and Qtimer is not triggered at the right time.

    When I binded the "playing" property of "AnimatedImage" object with its "visible" property, the cpu load is very much reduced(from around 100% to around 15%). Only when I open the page which has "AnimatedImage" object, the cpu load is increasing back to around 100%.

    Questions:

    Any idea why "AnimatedImage" is causing such a high cpu load. Any CPU intensive operations are done by QT which are specific to AnimatedImages? The "cache" property of the "AnimatedImage" is false in high CPU load scenario. But if I change "cache" to true and open the page with "AnimatedImage", cpu usage is around 35%( but it was more than 100% when "cache" is false). How "cache" property is affecting the cpu usage of "AnimatedImage"?

    Thanks in Advance.

  • 0 Votes
    1 Posts
    224 Views
    No one has replied
  • 0 Votes
    2 Posts
    730 Views
    JoeCFDJ

    @schrute

    QTimer timer; connect(timer, SIGNAL(timeout()), this, SLOT(timeoutFired())); timer.setInterval(10000); timer.start(); timeoutFired();====>call this func to start right away
  • 0 Votes
    11 Posts
    932 Views
    S

    @Axel-Spoerl The issue was with my build setup. After a clean build the debugger started behaving properly and I was able to resolve the crash.

  • 1 Votes
    8 Posts
    2k Views
    B

    @Chris-Kawa You know what I just realized... the QTimer::singleShot method doesn't even work because you won't know the remaining time if you pause again during the single shot.

  • My QTimer isnt working...

    Unsolved General and Desktop
    4
    0 Votes
    4 Posts
    371 Views
    jsulmJ

    @RuWex What do you think how long does "time" object exist here:

    void SendCommands::StartToSendCommand( QString fileName)//Ruth { Timer time(2000, fileName);

    ?

    Or "timer" here:

    button->show(); connect(button, &QPushButton::clicked, this, [=]() { statusBar()->showMessage(tr("Ready Start Testing"), 2000); Timer timer(num, fileName); });
  • 0 Votes
    2 Posts
    1k Views
    JKSHJ

    @Pandako said in QTimer Accuracy for Qt::PreciseTimer:

    But it exceeds 21ms or runs below 19ms sometimes, I was wondering, if someone would give me a hint about why this occurs?

    This is called "jitter".

    Windows is definitely not a real-time operating system (RTOS), and most Linux machines aren't either. This means the OS does not guarantee that your timers will always meet the intervals that you specify.

    If you truly need deterministic timers which guarantee that jitter levels are always below a certain threshold, then you need an RTOS.

    Qt officially supports a few commercial RTOS'es: INTEGRITY, VxWorks, and QNX Ubuntu also recently announced a beta version of a real-time kernel: https://ubuntu.com/engage/an-introduction-to-real-time-linux-part-i
  • 0 Votes
    2 Posts
    3k Views
    K

    OK, it was a bit premature to ask immediately.

    I found this post https://forum.qt.io/topic/54438/solved-qt-5-4-1-qtimer-using-up-all-handles-for-window-manager-objects

    Actually with QNetworkAccessManager I was a bit sloppy. Need to check if it helps already.

    Edit[koahnig]: It helped. Therefore, pay attention when generating new QNetworkAccessManger objects.

  • QTcpSocket Write

    Unsolved General and Desktop
    8
    0 Votes
    8 Posts
    900 Views
    A

    @duckrae List your client with id, when you are getting new incomingConnection. server can reply as per client id to a specific client or reply to all.

  • 0 Votes
    5 Posts
    1k Views
    JonBJ

    @DougyDrumz2 said in How do I make a QLabel Blink?:

    The consensus is evidently to l hide and show a QLabel

    Not my "consensus :) So far as I am aware, hiding can cause different layout redraw in at least some circumstances. I retain visibility but toggle foreground color to QColor(Qt::transparent) or toggle alpha color value between 255 (opaque) and 0 (transparent) on palette QPalette::setColor(QPalette::Text, colour).

    Also, creating multiple QTimer::singleShot()s doesn't scale very well if you want to change the number of flashes or the interval between. Or of you have multiple labels to blink and you'd like them all to be "in sync". I use one regular repeating QTimer with a "countdown" and cancellation when it reaches 0.

    Up to you on both of these.

  • 0 Votes
    4 Posts
    556 Views
    jsulmJ

    @duckrae said in How to write another Thread data in txt file?:

    How can I handle it?

    Simply emit the signal:

    QTimer *timer = new QTimer(this) timer->start(60000); emit myTimeoutSignal(text);
  • 0 Votes
    3 Posts
    704 Views
    JKSHJ

    @ActivateTheDroids said in What does "of" when used with QOverload do?:

    why is of there?

    Because of limitations in C++11.

    If you have C++14 support, then you don't need of: https://doc.qt.io/qt-5/signalsandslots-syntaxes.html#selecting-overloaded-signals-and-slots

  • 0 Votes
    5 Posts
    522 Views
    D

    @SGaist said in QTimer & Thread, adding it to running thread...:

    With only bits of your code it's not possible to understand your implementation and the possible issues you might be facing.

    Today is special day for my brain and I literally fail at basics... I forgot to start the worker... thus its event loop never run... thus it never started the damn timmer... ehhh!!!!

    Everything works fine once I started the worker... yayyyy I learned something new! :- )

  • Avoid dangling QTimer object

    Unsolved General and Desktop
    12
    0 Votes
    12 Posts
    2k Views
    JoeCFDJ

    Both QTimer timer and QTimer * timer{} are ok. The only difference is QTimer header file is included or not in the class header file.
    This is not an issue. If C++ is used, new and delete is not a problem. You do it all day long.

  • 0 Votes
    2 Posts
    2k Views
    Christian EhrlicherC

    Install a Qt message handler, set a breakpoint in there and take a look at the backtrace where it comes from.

  • Display text for 4 seconds

    Unsolved General and Desktop
    15
    0 Votes
    15 Posts
    2k Views
    JonBJ

    @User123456 said in Display text for 4 seconds:

    @JonB, I am using an old version, 4.5. I cannot just upgrade it since it is part of the requirements. Could you please give an example which will work on that version?

    Given that you appear to be a beginner, I am surprised you are using such an old version of Qt. That must mean you have an existing, pretty ancient Qt code base to work with. I understand it's not automatic/trivial to upgrade, but it's shame. If you post any future questions in this forum you should state each time that you are using Qt4, as it may be relevant to answers. Bear in mind when looking through documentation/examples you may need to check for Qt 4 ones/compatibility.

    Anyway, with an explicit method and not a lambda:

    // header file: private slots: void onTimeout(); // cpp file: void Dialog::onTimeout() { ui->LabelMessage->setText(""); } // caller: // next line connects using *new style* syntax, which is nicer... QTimer::singleShot(4000, this, &Dialog::onTimeout); // ... but if that doesn't work in Qt4 you can use *old style* syntax QTimer::singleShot(4000, this, SLOT(onTimeout()));
  • 0 Votes
    8 Posts
    2k Views
    Chris KawaC

    @TUStudi said:

    I actually have 6 QLabels, so I now have 6 timer and so on

    Derive a class from QLabel and add that functionality to it. Don't write the same code 6 times!

    My QLabels have the sizePolicy horizontal: preferred and vertical: fixed and a vertical length of 20.
    When a text is displayed, the QLabel expands so that the elements above the QLabel are also moved upwards and after the text disappears, they go back to their initial place.

    Fixed size policy means that widget uses its sizeHint() as the size. If you change the text the size hint also changes, so label grows/shrinks.

  • QTimers and QThreads

    Unsolved General and Desktop
    2
    0 Votes
    2 Posts
    470 Views
    jsulmJ

    @TMJJ001 said in QTimers and QThreads:

    connect(&cThread,SIGNAL(started()),this,SLOT(DoWork()));

    You do NOT execute DoWork() in that thread, you execute it in the GUI thread.
    Take a closer look at the example here: https://doc.qt.io/qt-5/qthread.html