Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, December 2006
[Qt4.1.5] QMenu::addAction QAction


Message 1 in thread

Hi all,

QAction* QMenu::addAction ( const QString& text, const QObject* 
receiver, const char* member, const QKeySequence& shortcut = 0 )

in Qt4.1.2 I could add a menu entry like this and everything worked fine:
QAction *a= menu->addAction( "test", this, SLOT( doSomething(bool) ) );

with Qt4.1.5 (I have not tested the versions inbetween) I get the 
following warning while running my application:

QObject::connect: Incompatible sender/receiver arguments
QAction::triggered() -> MainWindow::doSomething(bool)

One option to get it working again is:
QAction *a= menu->addAction( "test" );
connect( a, SIGNAL( triggered(bool) ), this, SLOT( doSomething(bool) ));

Anyways, I wonder if this was a bug in Qt4.1.2 or if it is a bug in Qt4.1.5.

Cheers,
Lothar

-- 
 [ signature omitted ] 

Message 2 in thread

On 12/2/06, Lothar Schlesier <qt@xxxxxxxxxxx> wrote:
> QObject::connect: Incompatible sender/receiver arguments
> QAction::triggered() -> MainWindow::doSomething(bool)

How does your slot look like? You sure it's a bool?

-- 
 [ signature omitted ] 

Message 3 in thread

Robin Ericsson schrieb:
> On 12/2/06, Lothar Schlesier <qt@xxxxxxxxxxx> wrote:
>> QObject::connect: Incompatible sender/receiver arguments
>> QAction::triggered() -> MainWindow::doSomething(bool)
> 
> How does your slot look like? You sure it's a bool?
> 

Here is a minimal example. Creating the QAction *a1 causes this error:
Object::connect: Incompatible sender/receiver arguments
         QAction::triggered() --> MainWindow::doSomething(bool)
in Qt4.1.5 but not in Qt4.1.2

#include <QtGui>

class MainWindow : public QMainWindow {
   Q_OBJECT

public:
   MainWindow();

private slots:
   void doSomething(bool);
};

MainWindow::MainWindow() {
   QMenuBar *menuBar = new QMenuBar();
   QMenu *menu = new QMenu( "test", menuBar );
   QAction *a1 = menu->addAction( "Problem", this, SLOT( 
doSomething(bool) ) );
   a1->setCheckable( TRUE );
   a1->setChecked( TRUE );
   QAction *a2= menu->addAction( "OK" );
   a2->setCheckable( TRUE );
   a2->setChecked( TRUE );
   connect( a2, SIGNAL( triggered(bool) ), this, SLOT( doSomething(bool) ));
   menuBar->addMenu( menu );
   setMenuBar( menuBar );
   resize( 100, 100 );
}

void
MainWindow::doSomething(bool test) {
   QString msg = "enabled";
   if (!test) msg = "disabled";

   QMessageBox::information(this, "Test", msg );
}


Cheers,
Lothar

-- 
 [ signature omitted ]