Portál AbcLinuxu, 1. listopadu 2025 21:03
/*
* Callback function for color buttons' "color-set" signal
*/
template< void (FunctionWidget::*func)(const FunctionColor&) >
void MainWindow::ColorSetter(GtkColorButton* but, MainWindow* win)
{
static GdkColor gc;
static FunctionColor fc;
gtk_color_button_get_color(but, &gc);
fc.set(gc, gtk_color_button_get_alpha(but));
FunctionWidget *w = win->function_widget;
(w->*func)(fc);
}
/*
* Create GtkColorButton which will automaticaly set function_widget color
* using "func" when "color-set" signal is emited
*/
template< void (FunctionWidget::*func)(const FunctionColor&) >
GtkColorButton* MainWindow::createColorButton(const FunctionColor& color, MainWindow* mw)
{
static GtkColorButton *result;
static GdkColor gdk_color;
static guint16 alpha;
color.toGdkColor(gdk_color, alpha);
result = (GtkColorButton*)gtk_color_button_new_with_color(&gdk_color);
gtk_color_button_set_use_alpha(result, TRUE);
gtk_color_button_set_alpha(result, alpha);
g_signal_connect(G_OBJECT(result), "color-set", G_CALLBACK(ColorSetter<func>), (gpointer)mw); /* GfMainWindow.h:80 hlášený v chybě */
return result;
}
Funkci volám takto:
createColorButton<&FunctionWidget::setBgColor>( function_widget->getBgColor(), this);A kompilátor hlásí
src/GfMainWindow.h: In static member function ‘static GtkColorButton* Gf::MainWindow::createColorButton(const Gf::FunctionColor&, Gf::MainWindow*) [with void (Gf::FunctionWidget::* func)(const Gf::FunctionColor&) = &Gf::FunctionWidget::setBgColor]’: src/GfMainWindow.cpp:97: instantiated from here src/GfMainWindow.h:80: error: insufficient contextual information to determine typePodle mě má však informací dost
template <> void MainWindow::ColorSetter<void (FunctionWidget::*func)(const FunctionColor&)> (GtkColorButton* but, MainWindow* win)Tohle vypadá jako nějaký tvar před ANSI.
void (*setter)(GtkColorButton*,MainWindow*) = MainWindow::ColorSetter< func >; g_signal_connect(G_OBJECT(result), "color-set", G_CALLBACK(setter), (gpointer)mw);A když to nechám přímo v tom G_CALLBACK, tak to neprojde ...
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.