boost.bind problems

O

Olaf Petzold

Hi,

at this time I try to combine Qt and boost. Unfortunately I've run into
trouble:

void QWidget::insertAction ( QAction * before, QAction * action );
class QAction : public QWidget { ... };

class ActionCategory {
...
QList<QAction*> m_actionList;
};

....
std::for_each(m_actionList.begin(), m_actionList.end(),
boost::bind(&QWidget::insertAction, _1, 0, _2));

which shall replace:

foreach(QAction* action, m_actionList)
insertAction(0, action);


What's wrong?

Thanks
Olaf

The error is:
Gui/ActionCategory.cpp: In member function »QMenu*
eda::ActionCategory::updateMenu(QMenu*)«:
Gui/ActionCategory.cpp:240: Fehler: expected `)' before numeric constant
/usr/include/boost/bind.hpp: At global scope:
/usr/include/boost/bind.hpp: In instantiation of
»boost::_bi::result_traits<boost::_bi::unspecified, void
(QWidget::*)(QAction*, QAction*)>«:
/usr/include/boost/bind/bind_template.hpp:15: instantiated from
»boost::_bi::bind_t<boost::_bi::unspecified, void (QWidget::*)(QAction*,
QAction*), boost::_bi::list2<boost::arg<1>, boost::arg<2> > >«
Gui/ActionCategory.cpp:240: instantiated from here
/usr/include/boost/bind.hpp:64: Fehler: »void (QWidget::*)(QAction*,
QAction*)« ist kein Klassen-, Struktur- oder Union-Typ
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:
In function »_Function std::for_each(_InputIterator, _InputIterator,
_Function) [with _InputIterator = QList<QAction*>::iterator, _Function =
boost::_bi::bind_t<boost::_bi::unspecified, void (QWidget::*)(QAction*,
QAction*), boost::_bi::list2<boost::arg<1>, boost::arg<2> > >]«:
Gui/ActionCategory.cpp:240: instantiated from here
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:159:
Fehler: keine Übereinstimmung für Aufruf von
»(boost::_bi::bind_t<boost::_bi::unspecified, void
(QWidget::*)(QAction*, QAction*), boost::_bi::list2<boost::arg<1>,
boost::arg<2> > >) (QAction*&)«
 
D

dasjotre

Hi,

at this time I try to combine Qt and boost. Unfortunately I've run into
trouble:

void QWidget::insertAction ( QAction * before, QAction * action );
class QAction : public QWidget { ... };

class ActionCategory {
...
QList<QAction*> m_actionList;

};

...
std::for_each(m_actionList.begin(), m_actionList.end(),
boost::bind(&QWidget::insertAction, _1, 0, _2));

for_each takes a unary function.
boost::bind(&QWidget::insertAction, _1, 0, _2)
creates a binary function and for_each will only
bind _1, _2 is left unbound
which shall replace:

foreach(QAction* action, m_actionList)
insertAction(0, action);

I suppose you want something like
std::for_each(m_actionList.begin(), m_actionList.end(),
boost::bind(&QWidget::insertAction, _1, 0, action) );
instead
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top