Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[RESOLVED] Console Application



  • Hello All,

    I develop a application that will every X seconds read a file.
    This already be done, but I have a big problem: I need keep the app running! I Use QTimer to Define the time of app read the file, but after read the first time the app stops to run.
    I just need keep this console app alive until send some kill signal or shutdown the machine.

    Any one can help me?
    Thanks all!



  • U should create "QApplication":qt-project.org/doc/qt-5/qapplication instance and call its "exec":http://qt-project.org/doc/qt-5/qapplication.html#exec method.



  • I'm using QCoreApplication! As you can see:

    @
    #include <QCoreApplication>
    #include <control/control.h>

    int main(int argc, char argv[])
    {
    QCoreApplication a(argc, argv);
    Control
    control = new Control(&a);
    control->start();
    return a.exec();
    }@

    I will try QApplication...



  • I got this error:

    /usr/bin/ld: cannot find -lGL
    collect2: error: ld returned 1 exit status
    make: *** [KismetLog] Error 1
    17:25:54: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project KismetLog (kit: Desktop Qt 5.3 GCC 64bit)
    When executing step "Make"

    I add to .pro this: "QT += core xml xmlpatterns widgets" and change the main:

    @
    //#include <QCoreApplication>
    #include <QApplication>

    #include <control/control.h>

    int main(int argc, char argv[])
    {
    // QCoreApplication a(argc, argv);
    QApplication a(argc, argv);
    Control
    control = new Control(&a);
    control->start();
    return a.exec();
    }
    @





  • Sorry guys... Just one error on my code!
    See you!

    Wrong:
    @
    if (this->timer = NULL) {
    @

    Correct:
    @
    if (this->timer == NULL) {
    @

    Very simple error. Thanks all.



  • Hi.
    it seems you have solved problem by yourself that's good.
    So, please update your thread title as [SOLVED] .
    Thanks.



  • Related, but you could use QFileSystemWatcher instead of timer for reading the file... Unless there is a reason why you want to read it every fixed amount of time. :-)



  • Yes I have to read every 60 seconds the file, I will process in the raspberry and send the processed information to a server.
    But I will take a look at QFileSystemWatcher, appears to be something very useful!

    Thanks for your tip!


Log in to reply