JPNaude / Qtilities

Building blocks for Qt applications
http://jpnaude.github.io/Qtilities/
Other
137 stars 39 forks source link

LoggerGui::createLogDockWidget returns null #115

Closed matrixspace closed 10 years ago

matrixspace commented 10 years ago

I just started to use Qtilities logging framework, I followed this document, trying to create a dock widget, but the LoggerGui::createLogDockWidget static function always returns null, the following is a snippet of my code.

MainWindow::MainWindow()
{
    setupUi(this);
    _glWindow = new DummyGLWindow;
    setCentralWidget(_glWindow);

    // trying to add a logging dockwidget
    QString log_engine_name = tr("Session Log");
    loggingDockWindow = Qtilities::CoreGui::LoggerGui::createLogDockWidget(&log_engine_name);
    Q_ASSERT(loggingDockWindow);
    loggingDockWindow->setAllowedAreas(Qt::DockWidgetArea::BottomDockWidgetArea);
    this->addDockWidget(Qt::BottomDockWidgetArea, loggingDockWindow);

    loadSettings();
}
CJCombrink commented 10 years ago

Hi,

What happens when you use createLogWidget() instead of the createLogDockWidget()? I am using the mentioned one with no problems (it is an older version of Qtilities though). (Your code seems correct)

matrixspace commented 10 years ago

@CJCombrink Actually inside createLogDockWidget() function, it uses createLogWidget() function to create a log widget, as the following code snippet shows:

QDockWidget* log_dock_widget = new QDockWidget(dock_name);
QWidget* log_widget = createLogWidget(engine_name,
                                     message_displays_flag,
                                     window_title,
                                     is_active,
                                     message_types,
                                     toolbar_area);
if (log_widget) {
log_dock_widget->setWidget(log_widget);
QObject::connect(log_widget,SIGNAL(destroyed()),log_dock_widget,SLOT(deleteLater()));
return log_dock_widget;
} else {
           delete log_dock_widget;
           return 0;
}

But unfortunately, the QWidget pointer that createLogWidget() returns is null, I'm trying to step into that and trace debugging. BTW, I'm using Qtilities 1.5, and I have integrated Qtilities into my project using CMake, wondering if that could be the cause of my problem...would you mind doing a little test on this? That would be appreciated!

matrixspace commented 10 years ago

@CJCombrink Problem solved, I read the source code, it seems Qtilities::Logging::Logger should be initialized before using, so I added this in my mainwindow constructor

Qtilities::Logging::Logger::instance()->initialize();

then it's all good.

JPNaude commented 10 years ago

Hi @daddybear1208. Thanks for reporting the issue. Yes, the logging framework needs to be initialized first. In normally do that in my main.cpp after initializing QApplication.

It probably makes sense to cout a warning telling you that this is required.