I have just gotten started with gtkmm and I am trying to update a label at a predefined interval by letting a timeout method call my Update() method. However, when writing the following line in the constructor of my MainWindow class:
Glib::signal_timeout().connect(sigc::mem_fun(*this, &MainWindow::Update), 1000);
I get the following error:
/usr/include/sigc++-2.0/sigc++/functors/slot.h:136:36: error: void value not ignored as it ought to be return (typed_rep->functor_)();
Does anybody have a clue on how to fix this or what is the cause?
Edit: Here is a minimal and reproducible example:
main.ccp
#include <gtkmm.h>
#include "MainWindow.h"
int main(int argc, char* argv[])
{
auto app = Gtk::Application::create(argc, argv, "com.companyname.test");
Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_file("prototype.glade");
MainWindow* mainWindow = 0;
builder->get_widget_derived("mainWindow", mainWindow);
return app->run(*mainWindow);
}
MainWindow.h
#pragma once
#include <gtkmm.h>
class MainWindow : public Gtk::Window
{
public:
MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade);
virtual ~MainWindow();
protected:
//Signal handlers:
void Update();
};
MainWindow.cpp
#include "MainWindow.h"
#include <iostream>
MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade)
{
// The following line creates "void value not ignored as it ought to be (...)" error
Glib::signal_timeout().connect(sigc::mem_fun(*this, &MainWindow::Update), 1000);
}
MainWindow::~MainWindow()
{
}
void MainWindow::Update()
{
std::cout << "Update" << std::endl;
}
MainWindow::Update
? – BobMoranesignal_timeout
expects a return value of typebool
but your handlerMainWindow::Update
isvoid
. – Scheff's Cattimeout_handler()
returnsfalse
the handler is disconnected. If you don't want this, just return constantlytrue
. If you don't like to change the signature ofMainWindow::Update()
, you could also wrap the handler into an adapter lambda:Glib::signal_timeout().connect(sigc::ptr_fun([this]() { Update(); return true; }), 1000);
. (I cannot check this on my side. Take it with a grain of salt.) – Scheff's CatGlib::signal_timeout().connect(sigc::bind_return(sigc::mem_fun(*this, &MainWindow::Update), true), 1000);
should work as well, of course. – Scheff's Cat