Reputation: 21
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;
}
Upvotes: 1
Views: 325
Reputation: 21
As Scheff mentioned in the comments, I forgot that MainWindow::Update
needs to return a value of type bool
, as that is expected by signal_timeout
. Changing the Update method to the following, fixed the issue:
bool MainWindow::Update()
{
std::cout << "Update" << std::endl;
return true;
}
Upvotes: 1