Skip to content
  • 0 Votes
    3 Posts
    270 Views
    J

    @JonB thank you

  • 0 Votes
    3 Posts
    424 Views
    D

    @Dean21 I just figured this out myself and am just posting in case someone else has the same issue.

    My function where I want the timer now looks like shown below:

    QObject::connect(&client, &QMMqttClient::onMessageReceived, [this](const QString &topic, const QByteArray &msg) { ui->Alarm_Triggered_Label->setText("Temperature alarm of PSU triggered, HV output disabled for 5 minutes"); ui->HV_ON_OFF_Button->setEnabled(false); // Use QMetaObject::invokeMethod to execute the code in the main GUI thread QMetaObject::invokeMethod(this, "publishAfterDelay", Qt::QueuedConnection); });

    And the call to function publishAfterDelay() looks like shown below:

    void Widget::publishAfterDelay() { QTimer::singleShot(3000, this, [this]() { client.publishMesage("Alarm_5_min_cooldown_complete", "1"); qDebug() << "timer pinged"; }); }

    Hope this helps anyone else.

  • 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.

  • 0 Votes
    3 Posts
    628 Views
    GrecKoG

    Use a SequentialAnimation and put a PauseAnimation in it first, with a duration depending on the index of the delegate.

  • 0 Votes
    17 Posts
    1k Views
    haykarmeniH

    thank you, @eyllanesc, now it works as I expect...thank you very much for so much assistance and readiness :)

  • 0 Votes
    12 Posts
    1k Views
    aminaA

    @amina

    I posted this in an other forum because it has been a while that I am stuck and it has to be fixed .. I am going to share the solution it may help someone https://stackoverflow.com/questions/66869600/timer-couldnt-work-with-wiringpiisr-qtquick-application/66873812?noredirect=1#comment118230663_66873812

    static instances of QObject are also not supported

    so the instance vitesse should be created after QApplication.
    this will fix the problem :

    static void isrInput_vitesse(); static Capteur_Input *vitesse = nullptr; static void isrInput_vitesse() { if(!vitesse) //not initialized yet return; QMetaObject::invokeMethod( vitesse, "isrCallback", Qt::QueuedConnection ); //or blockingQueue if you need to handle it directly in Qt way. } and in the main fucntion int main(int argc, char *argv[]) { QApplication a(argc, argv); //..... your main application body vitesse = new Capteur_Input(Pin_vitesse,PUD_OFF,INT_EDGE_RISING,isrInput_vitesse); ctx->setContextProperty("vitesse", vitesse); //... }

    the function isrCallback should be a slot

  • 0 Votes
    28 Posts
    4k Views
    mrjjM

    @SGaist
    Good catch.
    yes its x,y.
    It was more about num being undeclared at that point in time :)
    Changed as not to confuse future readers.

  • 0 Votes
    2 Posts
    310 Views
    Christian EhrlicherC

    Already asked and answered here: https://forum.qt.io/topic/122197

  • 0 Votes
    9 Posts
    2k Views
    KroMignonK

    @SyntaX said in Timer stops/pauses if Activity is suspended in Android:

    Do I just send an Email to android-development@qt-project.org and everyone who is subscribed gets the message? Seems a bit of a overkill like @everyone to me?

    No problem, you first have to register to the mailing list, and then you can send emails to it. This is the Qt-Android developers mailing list. So your mail will be received by each member.
    That's the way mailing lists works ;-)

    You can also try to contact BogDan Vatra from KDAB, which is the main developer of Qt/Android

  • 0 Votes
    7 Posts
    750 Views
    M

    @chehrlic said in Write Scheduler to run different pointer to member:

    I still don't see why a QTimer isn't enough - it can be started, stopped, can be run once or more, can execute any function given with any kind of parameters, even a lambda, ... there is nothing your description requires you to store the PMF by your own. But maybe QMetaMethod is something you can take a look on

    Well, like you said, QTimer alone could be enough at first sight, but if I want to "manage" them, or even organize them, I need a wrapper with some human-readable data. That's when the Task class comes handy.

    This is my current Task class, as of today:

    class Task : public QObject { Q_OBJECT public: typedef std::function<bool(QString&)> Function; private: QString m_name; Function m_function; QDateTime m_firstExec; int m_frequency; const Task *m_depends; QDateTime m_lastExec; bool m_lastStatus; QString m_failedReason; QMetaObject::Connection m_dependCnt; public: // Constructors/Getters/Setters signals: void starting(); void finished(bool status); public slots: void schedule(); void exec(); };

    I'm stuck with a single type of Function stored (bool (QString&)), with the m_depends property I can wait for another Task to emit finished to effectively call schedule() (when I call schedule(), if there is a dependency, the task waits for the dependency's finished() to be emitted, then it calls schedule() on itself. When schedule() doesn't have to wait for anything, it calls QTimer::singleShot() with exec() as the slot, which itself calls the internal m_function stored.

    So I'm using a QTimer in the end, but with some extra properties. Except being stuck with a single type of function (I'm storing lambdas for now), I'm pretty happy with that, moreover if I need to build a widget showing the status of each of them.

    I will look at QMetaMethod also, thanks for your suggestions

  • 0 Votes
    5 Posts
    2k Views
    G

    @dheerendra Okay, done, thank you for reminding!

  • 0 Votes
    4 Posts
    954 Views
    G

    I tried some different options, and found a solution:

    void MainWindow::saveSettings() { name = (QCoreApplication::applicationDirPath() +"/logs/"+ui->lineEdit->text() +".txt"); QFile file (name) ; if (newfile == true){ if (file.exists()){ qDebug ()<<"already exists"; NewLog(); timer->stop(); } else { qDebug()<< "Does not exist"; file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append); QString c_time = QTime::currentTime().toString(); QString sText =QString::number(update) + ". "+ c_time + ": rpm = "+ rpm + ", load = "+ QString::number(load) + ", " + name1+ " = " + result1 + ", "+ name2+ " = " + result2 + ", " + name3+ " = " + result3 + ", "+ name4+ " = " + result4 + ", " + name5+ " = " + result5 + ", "+ name6+ " = " + result6 + ", " + name7+ " = " + result7 + ", "+ name8+ " = " + result8 + ", " + name9+ " = " + result9 + ", "+ name10+ " = " + result10; ui->label_log->setText(sText); update++; QTextStream out(&file); out << sText + "\n"; file.close(); newfile = false; }}else{ file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append); QString c_time = QTime::currentTime().toString(); QString sText =QString::number(update) + ". "+ c_time + ": rpm = "+ rpm + ", load = "+ QString::number(load) + ", " + name1+ " = " + result1 + ", "+ name2+ " = " + result2 + ", " + name3+ " = " + result3 + ", "+ name4+ " = " + result4 + ", " + name5+ " = " + result5 + ", "+ name6+ " = " + result6 + ", " + name7+ " = " + result7 + ", "+ name8+ " = " + result8 + ", " + name9+ " = " + result9 + ", "+ name10+ " = " + result10; ui->label_log->setText(sText); update++; QTextStream out(&file); out << sText + "\n"; file.close(); }}

    Maybe it can be easier, but i am still learning. Thanks for your input.
    If you have comments on how to change my code, please tell me.
    (newlog was only to test something else now)

  • 0 Votes
    4 Posts
    2k Views
    C

    I think that your question is not specifique enough

    What you can do is to derive from QWidget (creating a new class)
    In this class compose a QTimer object:

    http://doc.qt.io/qt-5/qtimer.html

    Then your widget is a empty box that have the functionality of a QTimer....

    If you required that the QWidget has only one shot per click (guessing), you would like to use the static function SingleShot http://doc.qt.io/qt-5/qtimer.html#singleShot

    Kind Regards,

    Carlos

  • QML Timer and Loader

    Unsolved QML and Qt Quick
    3
    0 Votes
    3 Posts
    2k Views
    p3c0P

    @Mark81 The example works. Is there anything else that is missing ?

  • 0 Votes
    4 Posts
    2k Views
    SGaistS

    That's what the timer is for. If you press the key long enough then it will fire but if you release it quicker that the timeout, the timer will be cancelled, no need to measure the time between both events.

  • 0 Votes
    2 Posts
    911 Views
    CharbyC

    @QtGuy said:

    Component.onCompleted: {

    Remove the ":"

  • 0 Votes
    2 Posts
    1k Views
    JKSHJ

    Hi,

    There is no built-in timer GUI component. However, you can run a QML Timer and use it to update the text in your GUI.

  • 0 Votes
    2 Posts
    1k Views
    Q

    Pushing again.

  • 0 Votes
    4 Posts
    2k Views
    SGaistS

    When does it start to show that A ?

  • 0 Votes
    8 Posts
    4k Views
    ?

    @maximus Hi! Have a look at this blog post: https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/