1
votes

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;
}
1
Please port a minimal and reproducible example. For example, what is the code behind MainWindow::Update?BobMorane
Sorry, added it now!JesseL
Please, have a look at the doc.Glib::SignalTimeout. The signal_timeout expects a return value of type bool but your handler MainWindow::Update is void.Scheff's Cat
The meaning of the return value: If timeout_handler() returns false the handler is disconnected. If you don't want this, just return constantly true. If you don't like to change the signature of MainWindow::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 Cat
Yeah. I hate the binds and love the adapter lambdas. However, Glib::signal_timeout().connect(sigc::bind_return(sigc::mem_fun(*this, &MainWindow::Update), true), 1000); should work as well, of course.Scheff's Cat

1 Answers

1
votes

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;
}