Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Add to Qt GUI logger functionality
Forum Update on Monday, May 27th 2025

Add to Qt GUI logger functionality

Scheduled Pinned Locked Moved Unsolved Qt 6
27 Posts 4 Posters 3.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gaetano03
    wrote on 21 Apr 2022, 07:50 last edited by
    #1

    Hi there,

    I am trying to design a Qt GUI to control some hardware components and I am planning to insert to the interface also a console output (kind of logger) which prints messages/warning/failures coming from the different instruments.

    I was googling around and it seems to me the best way to do this at the level of the graphical interface is using QPlainText Widget (set to Read Only).

    Any recommendation on that? But more importantly, how to design this on the backend side?

    Actually I already have a logger library which launches a thread and handles the queue of messages (coming from the various instruments ) to write on a log file.

    Is there a recommended way to connect such an external library to my GUI (in particular to the QPlainText in order to write messages from the queue)?

    Thanks a lot,

    Any help or link share will be much appreciated :)

    J 1 Reply Last reply 21 Apr 2022, 07:55
    0
    • G Gaetano03
      21 Apr 2022, 07:50

      Hi there,

      I am trying to design a Qt GUI to control some hardware components and I am planning to insert to the interface also a console output (kind of logger) which prints messages/warning/failures coming from the different instruments.

      I was googling around and it seems to me the best way to do this at the level of the graphical interface is using QPlainText Widget (set to Read Only).

      Any recommendation on that? But more importantly, how to design this on the backend side?

      Actually I already have a logger library which launches a thread and handles the queue of messages (coming from the various instruments ) to write on a log file.

      Is there a recommended way to connect such an external library to my GUI (in particular to the QPlainText in order to write messages from the queue)?

      Thanks a lot,

      Any help or link share will be much appreciated :)

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 21 Apr 2022, 07:55 last edited by
      #2

      @Gaetano03 said in Add to Qt GUI logger functionality:

      Is there a recommended way to connect such an external library to my GUI

      Does this lib use Qt? If so you could use signals/slots to send log messages as signal parameter to your QPlainText.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Gaetano03
        wrote on 21 Apr 2022, 08:23 last edited by
        #3

        Actually not, it is an external library just using std libraries :/

        J 1 Reply Last reply 21 Apr 2022, 08:53
        0
        • G Gaetano03
          21 Apr 2022, 08:23

          Actually not, it is an external library just using std libraries :/

          J Offline
          J Offline
          JonB
          wrote on 21 Apr 2022, 08:53 last edited by JonB
          #4

          @Gaetano03
          Then how are you going to know when it calls std::... whatever to output/append a message, so that you can react to it to put it into your QPlainText? Especially if you cannot change its source code. Sounds like you might have to monitor its output file (if that's where it writes to) via QFileSystemWatcher class if it is such a "closed" system?

          G 1 Reply Last reply 21 Apr 2022, 10:47
          0
          • J JonB
            21 Apr 2022, 08:53

            @Gaetano03
            Then how are you going to know when it calls std::... whatever to output/append a message, so that you can react to it to put it into your QPlainText? Especially if you cannot change its source code. Sounds like you might have to monitor its output file (if that's where it writes to) via QFileSystemWatcher class if it is such a "closed" system?

            G Offline
            G Offline
            Gaetano03
            wrote on 21 Apr 2022, 10:47 last edited by
            #5

            @JonB I actually can access the source code of the logger library

            So best way would be to act directly on that library and modify it to be a Qt library?

            J 1 Reply Last reply 21 Apr 2022, 10:49
            0
            • G Gaetano03
              21 Apr 2022, 10:47

              @JonB I actually can access the source code of the logger library

              So best way would be to act directly on that library and modify it to be a Qt library?

              J Offline
              J Offline
              JonB
              wrote on 21 Apr 2022, 10:49 last edited by JonB
              #6

              @Gaetano03
              That --- or something similar --- would be the best/easiest if you need your Qt UI program to know when/what the external library does in the way of issuing some message which you would like the UI to know about, so that it can put it in its QPlainText. That is what @jsulm had in mind when he wrote:

              Does this lib use Qt? If so you could use signals/slots to send log messages as signal parameter to your QPlainText.

              You could probably also do it by having the lib not know about Qt but have an exported "function pointer". If the calling program (Qt) sets that to a non-nullptr static function in itself, the library could call that and then the Qt program act on it (e.g. emit a signal). That's if you don't want your library to know anything about Qt.

              G 1 Reply Last reply 21 Apr 2022, 11:07
              0
              • J JonB
                21 Apr 2022, 10:49

                @Gaetano03
                That --- or something similar --- would be the best/easiest if you need your Qt UI program to know when/what the external library does in the way of issuing some message which you would like the UI to know about, so that it can put it in its QPlainText. That is what @jsulm had in mind when he wrote:

                Does this lib use Qt? If so you could use signals/slots to send log messages as signal parameter to your QPlainText.

                You could probably also do it by having the lib not know about Qt but have an exported "function pointer". If the calling program (Qt) sets that to a non-nullptr static function in itself, the library could call that and then the Qt program act on it (e.g. emit a signal). That's if you don't want your library to know anything about Qt.

                G Offline
                G Offline
                Gaetano03
                wrote on 21 Apr 2022, 11:07 last edited by
                #7

                @JonB Thanks a lot!

                Yep that was the original idea: having the logger not knowing anything about Qt.

                But might go back to first option, second one scares me a bit XD

                Do you have any examples, links to share on second option btw?

                Thanks again, appreciate a lot your help

                J J 2 Replies Last reply 21 Apr 2022, 11:13
                0
                • G Gaetano03
                  21 Apr 2022, 11:07

                  @JonB Thanks a lot!

                  Yep that was the original idea: having the logger not knowing anything about Qt.

                  But might go back to first option, second one scares me a bit XD

                  Do you have any examples, links to share on second option btw?

                  Thanks again, appreciate a lot your help

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 21 Apr 2022, 11:13 last edited by
                  #8

                  @Gaetano03 No need to be scared :-)

                  // Define a function pointer type
                  typedef void (*LoggerCallback)(std::string message);
                  
                  // A function to use as callback
                  void log(std::string message)
                  {
                      std::cout << message << std::endl;
                  }
                  
                  // Example how to use a function pointer (callBack) to call a function (log)
                  LoggerCallback callBack = &log;
                  callBack("Hello!");
                  

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2
                  • G Gaetano03
                    21 Apr 2022, 11:07

                    @JonB Thanks a lot!

                    Yep that was the original idea: having the logger not knowing anything about Qt.

                    But might go back to first option, second one scares me a bit XD

                    Do you have any examples, links to share on second option btw?

                    Thanks again, appreciate a lot your help

                    J Offline
                    J Offline
                    JonB
                    wrote on 21 Apr 2022, 12:35 last edited by JonB
                    #9

                    @Gaetano03 said in Add to Qt GUI logger functionality:

                    Do you have any examples, links to share on second option btw?

                    Basically what @jsulm has shown above. Certainly for type declaring. To make it clear where i have in mind what goes, the principle is:

                    • In some library logger.h file:
                    typedef void (*LoggerCallback)(std::string message);
                    extern LoggerCallback g_loggerCallback;
                    
                    • In some library logger.cpp file:
                    #include "logger.h"
                    LoggerCallback g_loggerCallback = nullptr;
                    ...
                    void libraryLoggingFunction(std::string message)
                    {
                        selfLoggingWhatever(message);
                        if (g_loggerCallback != nullptr)
                            g_loggerCallback(message);
                    }
                    
                    • In one of your Qt app .cpp files:
                    #include "library/logger.h"
                    ...
                    g_loggerCallback = log;
                    ...
                    void log(std::string message)
                    {
                        emit libraryLogged(message);
                    }
                    

                    Something along these lines. The point is that the library has a g_loggerCallback exported variable. It is set to nullptr initially, in which case it is never called/used. You can link it as-is with any outside-world which knows/cares nothing about the existence of the function pointer variable. The library still knows nothing about Qt.

                    If and only if the outside-world program the library is linked with chooses to set g_loggerCallback to a suitable logging function of its own then that will be called by the library's if (g_loggerCallback != nullptr) ... logging code. Whereupon the host Qt or otherwise application can decide what to do with the message in its callback function.

                    1 Reply Last reply
                    2
                    • G Offline
                      G Offline
                      Gaetano03
                      wrote on 21 Apr 2022, 13:44 last edited by
                      #10

                      Thanks a lot to both :))) . That is actually amazing!

                      So if I understood well, the last add will be to catch that signal from QPlainText and that's it?!?!

                      Really appreciated your help guys :)

                      J 1 Reply Last reply 21 Apr 2022, 14:10
                      0
                      • G Gaetano03
                        21 Apr 2022, 13:44

                        Thanks a lot to both :))) . That is actually amazing!

                        So if I understood well, the last add will be to catch that signal from QPlainText and that's it?!?!

                        Really appreciated your help guys :)

                        J Offline
                        J Offline
                        JonB
                        wrote on 21 Apr 2022, 14:10 last edited by JonB
                        #11

                        @Gaetano03 said in Add to Qt GUI logger functionality:

                        So if I understood well, the last add will be to catch that signal from QPlainText and that's it?!?!

                        Yes. The "tricky" bit, I think, is that you need a QObject-derived object to emit any signal. And the function your Qt app will need to set, like g_loggerCallback = log;, will I believe not be able to be a member of any class, it will need to be global/static. I think you will need that log function to have access to a global QObject object, e.g. it may have to call on your QApplication global object, or perhaps some other singleton class, to emit a signal.

                        1 Reply Last reply
                        1
                        • G Offline
                          G Offline
                          Gaetano03
                          wrote on 21 Apr 2022, 15:01 last edited by
                          #12

                          @JonB said in Add to Qt GUI logger functionality:

                          QApplication a(argc, argv);
                          MainWindow w;
                          w.show();
                          return a.exec();

                          You mean on the "a" object in the application main? How would this be possible in such a case?

                          my understanding of what you are pointing out is that even if g_loggerCallback has global visibility, not sure what happens when it points to a QObject function (the call in the external logger library does not know what to do)?

                          What about making both the function pointer and the log function static? Maybe I am telling blasfemies, sorry for that

                          J 1 Reply Last reply 21 Apr 2022, 16:40
                          0
                          • G Gaetano03
                            21 Apr 2022, 15:01

                            @JonB said in Add to Qt GUI logger functionality:

                            QApplication a(argc, argv);
                            MainWindow w;
                            w.show();
                            return a.exec();

                            You mean on the "a" object in the application main? How would this be possible in such a case?

                            my understanding of what you are pointing out is that even if g_loggerCallback has global visibility, not sure what happens when it points to a QObject function (the call in the external logger library does not know what to do)?

                            What about making both the function pointer and the log function static? Maybe I am telling blasfemies, sorry for that

                            J Offline
                            J Offline
                            JonB
                            wrote on 21 Apr 2022, 16:40 last edited by JonB
                            #13

                            @Gaetano03
                            That a object in main() --- or rather, the QApplication object --- can be accessed from anywhere in a Qt program (because it's a singleton) via qApp macro or qGuiApp macro or QCoreApplication *QCoreApplication::instance(). That means you can use those anywhere in a Qt application, without worrying about the a variable in main().

                            You could use that to do something like create your own signal (must subclass QAppplication, but that's no problem), which you could connect() to a slot somewhere to update your QPlainText widget. Then even a static C function which is called from the function pointer we discussed can get at a Qt object to emit a signal. Or, you could skip signal/slot if you have, by whatever means, a global pointer to your desired QPlainText, which the static log function can use to set its text directly. Just be careful with coding, but it should be doable!

                            not sure what happens when it points to a QObject function (the call in the external logger library does not know what to do)?

                            All the external library knows is the outside world has set g_loggerCallback to the address of some function which takes a std:string (or whatever) as a parameter. That is all it needs to know to be able to call it. What happens at the other end in the function pointed to --- log(std::string message), which is in your Qt program, not the library --- is the other end's problem, so far as the library is concerned. [Which is why it would be nice if it worked and didn't crash :) ]

                            G 1 Reply Last reply 22 Apr 2022, 08:40
                            1
                            • J JonB
                              21 Apr 2022, 16:40

                              @Gaetano03
                              That a object in main() --- or rather, the QApplication object --- can be accessed from anywhere in a Qt program (because it's a singleton) via qApp macro or qGuiApp macro or QCoreApplication *QCoreApplication::instance(). That means you can use those anywhere in a Qt application, without worrying about the a variable in main().

                              You could use that to do something like create your own signal (must subclass QAppplication, but that's no problem), which you could connect() to a slot somewhere to update your QPlainText widget. Then even a static C function which is called from the function pointer we discussed can get at a Qt object to emit a signal. Or, you could skip signal/slot if you have, by whatever means, a global pointer to your desired QPlainText, which the static log function can use to set its text directly. Just be careful with coding, but it should be doable!

                              not sure what happens when it points to a QObject function (the call in the external logger library does not know what to do)?

                              All the external library knows is the outside world has set g_loggerCallback to the address of some function which takes a std:string (or whatever) as a parameter. That is all it needs to know to be able to call it. What happens at the other end in the function pointed to --- log(std::string message), which is in your Qt program, not the library --- is the other end's problem, so far as the library is concerned. [Which is why it would be nice if it worked and didn't crash :) ]

                              G Offline
                              G Offline
                              Gaetano03
                              wrote on 22 Apr 2022, 08:40 last edited by Gaetano03
                              #14

                              @JonB Getting a little bit of shakes now XD

                              "You could use that to do something like create your own signal (must subclass QAppplication, but that's no problem), which you could connect() to a slot somewhere to update your QPlainText widget. "

                              The other problem would be that signal and slot should be static as well? can you use connect on static objects?

                              If I understand well, your first option would be to create a class that inherits Qapplication and get an instance of the Qapplication. Here I define my own signal (static?) which I then emits thorugh the log function defined above (still static). This should be catched by the QPlainText widget, but at this point how? Should I make the slot static as well? Actually it seems I am getting real troubles when I try to use connect with static methods.

                              Will investigate also second option

                              Thanks a lot

                              J 1 Reply Last reply 22 Apr 2022, 09:04
                              0
                              • G Gaetano03
                                22 Apr 2022, 08:40

                                @JonB Getting a little bit of shakes now XD

                                "You could use that to do something like create your own signal (must subclass QAppplication, but that's no problem), which you could connect() to a slot somewhere to update your QPlainText widget. "

                                The other problem would be that signal and slot should be static as well? can you use connect on static objects?

                                If I understand well, your first option would be to create a class that inherits Qapplication and get an instance of the Qapplication. Here I define my own signal (static?) which I then emits thorugh the log function defined above (still static). This should be catched by the QPlainText widget, but at this point how? Should I make the slot static as well? Actually it seems I am getting real troubles when I try to use connect with static methods.

                                Will investigate also second option

                                Thanks a lot

                                J Offline
                                J Offline
                                JonB
                                wrote on 22 Apr 2022, 09:04 last edited by
                                #15

                                @Gaetano03
                                The only thing which needs to be "static" is the global, non-member function void log(std::string message), to which you set g_loggerCallback = log;, so that the library can invoke it via g_loggerCallback(message).

                                That can go something like:

                                void log(std::string message)
                                {
                                    emit qApp()->libraryLogged(message);
                                    // or probably
                                    MyApplication *myApp = qobject_cast<MyApplication *>(qApp());
                                    emit myApp->libraryLogged(message);
                                }
                                

                                You would need to subclass and use QApplication something like:

                                class MyApplication : public QApplication
                                {
                                signals:
                                    void libraryLogged(std::string message);
                                }
                                

                                Now it remains to have done the connect(). Somewhere in your code which can "see" wherever you create the QTextEdit *logmessageTextEdit = new QTextEdit, or afterwards, and can see the class MyApplication definition, needs e.g.

                                MyApplication *myApp = qobject_cast<MyApplication *>(qApp());
                                connect(myApp(), &MyApplication::libraryLogged, this, &ThisClass::onLibraryLogged);
                                
                                class ThisClass
                                {
                                slots:
                                    void onLibraryLogged(std::string message) { this->logmessageTextEdit->append(message); }
                                }
                                

                                Alternatively, if you don't want to use signals/slots, keep some global reference to the logmessageTextEdit pointer to the QTextEdit and just go

                                void log(std::string message)
                                {
                                    if (g_logmessageTextEdit != nullptr)
                                        g_logmessageTextEdit->append(message);
                                }
                                
                                G 1 Reply Last reply 22 Apr 2022, 10:51
                                0
                                • J JonB
                                  22 Apr 2022, 09:04

                                  @Gaetano03
                                  The only thing which needs to be "static" is the global, non-member function void log(std::string message), to which you set g_loggerCallback = log;, so that the library can invoke it via g_loggerCallback(message).

                                  That can go something like:

                                  void log(std::string message)
                                  {
                                      emit qApp()->libraryLogged(message);
                                      // or probably
                                      MyApplication *myApp = qobject_cast<MyApplication *>(qApp());
                                      emit myApp->libraryLogged(message);
                                  }
                                  

                                  You would need to subclass and use QApplication something like:

                                  class MyApplication : public QApplication
                                  {
                                  signals:
                                      void libraryLogged(std::string message);
                                  }
                                  

                                  Now it remains to have done the connect(). Somewhere in your code which can "see" wherever you create the QTextEdit *logmessageTextEdit = new QTextEdit, or afterwards, and can see the class MyApplication definition, needs e.g.

                                  MyApplication *myApp = qobject_cast<MyApplication *>(qApp());
                                  connect(myApp(), &MyApplication::libraryLogged, this, &ThisClass::onLibraryLogged);
                                  
                                  class ThisClass
                                  {
                                  slots:
                                      void onLibraryLogged(std::string message) { this->logmessageTextEdit->append(message); }
                                  }
                                  

                                  Alternatively, if you don't want to use signals/slots, keep some global reference to the logmessageTextEdit pointer to the QTextEdit and just go

                                  void log(std::string message)
                                  {
                                      if (g_logmessageTextEdit != nullptr)
                                          g_logmessageTextEdit->append(message);
                                  }
                                  
                                  G Offline
                                  G Offline
                                  Gaetano03
                                  wrote on 22 Apr 2022, 10:51 last edited by
                                  #16

                                  @JonB said in Add to Qt GUI logger functionality:

                                  Not sure where to declare the log function though

                                  At this point what I did is

                                  I created a QApplication subclass in a .h file (integer_interface.h) which looks like this

                                  class integer_interface : public QApplication
                                  {
                                      Q_OBJECT
                                  public:
                                      integer_interface(int &argc, char *argv[]) {}; // empty constructor
                                  
                                  signals:
                                      void libraryLogged(std::string message);
                                  
                                  };
                                  

                                  then in my logger_widget class, logger_widget.h (the one that contains the QPlainTextWidget) I have the following class definition:

                                  namespace Ui {
                                  class logger_widget; 
                                  }
                                  
                                  class logger_widget : public QWidget
                                  {
                                      Q_OBJECT
                                  
                                  public:
                                      explicit logger_widget(QWidget *parent = nullptr);
                                      ~logger_widget();
                                  
                                  signals:
                                  
                                  
                                  public slots:
                                      void onLibraryLogged(std::string message);
                                  
                                  
                                  private:
                                      Ui::logger_widget *ui;
                                  
                                      integer::logger::errors err_init;
                                      integer::logger::integer_logger& logger = integer::logger::integer_logger::get_instance();
                                      integer_interface *myApp = qobject_cast<integer_interface *>(qApp);
                                  
                                  };
                                  

                                  and a declaration of the log static function outside the class

                                  static void log(std::string message); 
                                  

                                  In the logger_widget constructor I have the following two lines to define the connection

                                  integer::logger::g_loggerCallback = log;
                                  connect(myApp,&integer_interface::libraryLogged,this,&logger_widget::onLibraryLogged);
                                  

                                  while log and onLibraryLogged implementations look like this

                                  void logger_widget::onLibraryLogged(std::string message)
                                  {
                                      ui->plainTextEdit_logger->appendPlainText(QString::fromStdString(message));
                                  }
                                  
                                  void log(std::string message)
                                  {
                                      integer_interface *myApp = qobject_cast<integer_interface *>(qApp);
                                      emit myApp->libraryLogged(message);
                                  }
                                  

                                  constructor and function implementations are obviously in the corresponding logger_widget.cpp file

                                  It compiles fine, but I get a runtime error "abort()" and the following message

                                  qt.core.qobject.connect: QObject::connect(integer_interface, logger_widget): invalid nullptr parameter
                                  
                                  J 1 Reply Last reply 22 Apr 2022, 11:09
                                  0
                                  • G Gaetano03
                                    22 Apr 2022, 10:51

                                    @JonB said in Add to Qt GUI logger functionality:

                                    Not sure where to declare the log function though

                                    At this point what I did is

                                    I created a QApplication subclass in a .h file (integer_interface.h) which looks like this

                                    class integer_interface : public QApplication
                                    {
                                        Q_OBJECT
                                    public:
                                        integer_interface(int &argc, char *argv[]) {}; // empty constructor
                                    
                                    signals:
                                        void libraryLogged(std::string message);
                                    
                                    };
                                    

                                    then in my logger_widget class, logger_widget.h (the one that contains the QPlainTextWidget) I have the following class definition:

                                    namespace Ui {
                                    class logger_widget; 
                                    }
                                    
                                    class logger_widget : public QWidget
                                    {
                                        Q_OBJECT
                                    
                                    public:
                                        explicit logger_widget(QWidget *parent = nullptr);
                                        ~logger_widget();
                                    
                                    signals:
                                    
                                    
                                    public slots:
                                        void onLibraryLogged(std::string message);
                                    
                                    
                                    private:
                                        Ui::logger_widget *ui;
                                    
                                        integer::logger::errors err_init;
                                        integer::logger::integer_logger& logger = integer::logger::integer_logger::get_instance();
                                        integer_interface *myApp = qobject_cast<integer_interface *>(qApp);
                                    
                                    };
                                    

                                    and a declaration of the log static function outside the class

                                    static void log(std::string message); 
                                    

                                    In the logger_widget constructor I have the following two lines to define the connection

                                    integer::logger::g_loggerCallback = log;
                                    connect(myApp,&integer_interface::libraryLogged,this,&logger_widget::onLibraryLogged);
                                    

                                    while log and onLibraryLogged implementations look like this

                                    void logger_widget::onLibraryLogged(std::string message)
                                    {
                                        ui->plainTextEdit_logger->appendPlainText(QString::fromStdString(message));
                                    }
                                    
                                    void log(std::string message)
                                    {
                                        integer_interface *myApp = qobject_cast<integer_interface *>(qApp);
                                        emit myApp->libraryLogged(message);
                                    }
                                    

                                    constructor and function implementations are obviously in the corresponding logger_widget.cpp file

                                    It compiles fine, but I get a runtime error "abort()" and the following message

                                    qt.core.qobject.connect: QObject::connect(integer_interface, logger_widget): invalid nullptr parameter
                                    
                                    J Offline
                                    J Offline
                                    JonB
                                    wrote on 22 Apr 2022, 11:09 last edited by JonB
                                    #17

                                    @Gaetano03
                                    So I assume that occurs at runtime when it hits

                                    connect(myApp,&integer_interface::libraryLogged,this,&logger_widget::onLibraryLogged);
                                    

                                    and indicates one of the two objects are nullptr. Check on line above with e.g.

                                    qDebug() << myApp << this;
                                    

                                    ?

                                    If myApp == nullptr, you did remember to create an integer_interface, not just a QApplication now, didn't you...??

                                    Everywhere you go integer_interface *myApp = qobject_cast<integer_interface *>(qApp); you might follow that with Q_ASSERT(myApp); to verify all is well at that instant.

                                    P.S.

                                    integer_interface(int &argc, char *argv[]) {}; // empty constructor

                                    Do you have integer_interface(int &argc, char *argv[]) : QApplication(argc, argv) somewhere?

                                    G J 2 Replies Last reply 22 Apr 2022, 11:40
                                    0
                                    • J JonB
                                      22 Apr 2022, 11:09

                                      @Gaetano03
                                      So I assume that occurs at runtime when it hits

                                      connect(myApp,&integer_interface::libraryLogged,this,&logger_widget::onLibraryLogged);
                                      

                                      and indicates one of the two objects are nullptr. Check on line above with e.g.

                                      qDebug() << myApp << this;
                                      

                                      ?

                                      If myApp == nullptr, you did remember to create an integer_interface, not just a QApplication now, didn't you...??

                                      Everywhere you go integer_interface *myApp = qobject_cast<integer_interface *>(qApp); you might follow that with Q_ASSERT(myApp); to verify all is well at that instant.

                                      P.S.

                                      integer_interface(int &argc, char *argv[]) {}; // empty constructor

                                      Do you have integer_interface(int &argc, char *argv[]) : QApplication(argc, argv) somewhere?

                                      G Offline
                                      G Offline
                                      Gaetano03
                                      wrote on 22 Apr 2022, 11:40 last edited by
                                      #18

                                      @JonB
                                      I think the problem might be where I define myApp is not correct? Which is at the moment into the logger_widget class

                                      when I qDebug as you said I get indeed the following value for myApp

                                      QObject(0x0) logger_widget(0x1e04f63bcd0, name="logger_widget")
                                      

                                      and the app crashes few seconds after it starts

                                      Should I declare the myApp out of any member class as I did for the log function?

                                      1 Reply Last reply
                                      0
                                      • J JonB
                                        22 Apr 2022, 11:09

                                        @Gaetano03
                                        So I assume that occurs at runtime when it hits

                                        connect(myApp,&integer_interface::libraryLogged,this,&logger_widget::onLibraryLogged);
                                        

                                        and indicates one of the two objects are nullptr. Check on line above with e.g.

                                        qDebug() << myApp << this;
                                        

                                        ?

                                        If myApp == nullptr, you did remember to create an integer_interface, not just a QApplication now, didn't you...??

                                        Everywhere you go integer_interface *myApp = qobject_cast<integer_interface *>(qApp); you might follow that with Q_ASSERT(myApp); to verify all is well at that instant.

                                        P.S.

                                        integer_interface(int &argc, char *argv[]) {}; // empty constructor

                                        Do you have integer_interface(int &argc, char *argv[]) : QApplication(argc, argv) somewhere?

                                        J Offline
                                        J Offline
                                        JonB
                                        wrote on 22 Apr 2022, 11:44 last edited by
                                        #19

                                        @Gaetano03

                                        @JonB said in Add to Qt GUI logger functionality:

                                        If myApp == nullptr, you did remember to create an integer_interface, not just a QApplication now, didn't you...??

                                        ??

                                        G 1 Reply Last reply 22 Apr 2022, 12:01
                                        0
                                        • J JonB
                                          22 Apr 2022, 11:44

                                          @Gaetano03

                                          @JonB said in Add to Qt GUI logger functionality:

                                          If myApp == nullptr, you did remember to create an integer_interface, not just a QApplication now, didn't you...??

                                          ??

                                          G Offline
                                          G Offline
                                          Gaetano03
                                          wrote on 22 Apr 2022, 12:01 last edited by
                                          #20

                                          @JonB

                                          Do you have integer_interface(int &argc, char *argv[]) : QApplication(argc, argv) somewhere?

                                          ye I have it in an integer_interface.cpp, looks like this

                                          #include "integer_interface.h"
                                          
                                          integer_interface::integer_interface(int &argc, char *argv[])
                                              : QApplication(argc, argv)
                                          {
                                          
                                          }
                                          

                                          ??

                                          I have it declared in my logger_widget.h class file (if you also see my previous reply), but was thinking maybe should be declared outside of the class?

                                          Or maybe you meant something else from this

                                          Christian EhrlicherC 1 Reply Last reply 22 Apr 2022, 12:03
                                          0

                                          1/27

                                          21 Apr 2022, 07:50

                                          • Login

                                          • Login or register to search.
                                          1 out of 27
                                          • First post
                                            1/27
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved