0

わかりましたので、これを実行すると(問題を表示するためだけに書きました):

#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QtGUI>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QWidget *window = new QWidget;

    QPushButton *MainInter = new QPushButton("Push me!",window);

    QObject::connect(MainInter,SIGNAL(released()),MainInter,SLOT(move(100,100)));

    window->resize(900,500);
    window->show();
    return a.exec();
}

クリックしてもボタンが動かないのはなぜですか? :)

4

2 に答える 2

1

シグナルとスロットは同じ署名を持つ必要があります。実際には、スロットはシグナルよりも短い署名を持つことができます:

http://qt-project.org/doc/qt-4.8/signalsandslots.html

In your case, it's the opposite: slot has a longer signature. You may try QSignalMapper to create a "broker" to relay the signal with additional parameters.

于 2012-08-25T02:34:59.010 に答える
0

moveはスロットではなく、posプロパティを変更するためのアクセサーであるため、信号に直接接続することはできません。ただし、そのプロパティを変更するstart()スロットに信号を接続できます。QPropertyAnimation

QPushButton *MainInter = new QPushButton("Push me!",window);

QPropertyAnimation *animation = new QPropertyAnimation(MainInter, "pos");
// To make the move instantaneous
animation->setDuration(0);
animation->setEndValue(QPoint(100,100));

QObject::connect(MainInter, SIGNAL(released()), animation, SLOT(start()));
...

または、そのプロパティ値を a の状態の一部にしQStateMachine、信号を使用してその状態に遷移します。

QPushButton *MainInter = new QPushButton("Push me!",window);

QStateMachine *machine = new QStateMachine();
QState *s1 = new QState(machine);
QState *s2 = new QState(machine);
// the transition replaces the connect statement
s1->addTransition(MainInter, SIGNAL(released()), s2);
s2->assignProperty(MainInter, "pos", QPoint(100,100));
machine->setInitialState(s1);
machine->start();    
...
于 2012-08-25T23:01:23.987 に答える