本文整理汇总了C++中QStateMachine::setInitialState方法的典型用法代码示例。如果您正苦于以下问题:C++ QStateMachine::setInitialState方法的具体用法?C++ QStateMachine::setInitialState怎么用?C++ QStateMachine::setInitialState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStateMachine
的用法示例。
在下文中一共展示了QStateMachine::setInitialState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupStateMachine
void MainWindow::setupStateMachine()
{
// set title bar text
this->setWindowTitle(QString("Excape From Estes"));
// create the state machine object and its states
QStateMachine *machine = new QStateMachine(this);
QState *s1 = new QState();
QState *s2 = new QState();
QState *s3 = new QState();
// assign an event for every state
s1->assignProperty(ui->label, "text", readFile("intro.txt"));
s2->assignProperty(ui->label, "text", "In state s2");
s3->assignProperty(ui->label, "text", "In state s3");
// set up a trigger to end every state
s1->addTransition(this, SIGNAL(one()), s2);
s2->addTransition(this, SIGNAL(two()), s3);
s3->addTransition(this->ui->pushButton, SIGNAL(clicked()), s1);
// add the states to the state machine and set a starting state
machine->addState(s1);
machine->addState(s2);
machine->addState(s3);
machine->setInitialState(s1);
// enable the machine and print out a message to show that we are done
machine->start();
qDebug() << "State Machine Created";
}
示例2: main
//! [4]
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QStateMachine machine;
QState *group = new QState(QState::ParallelStates);
group->setObjectName("group");
//! [4]
//! [5]
Pinger *pinger = new Pinger(group);
pinger->setObjectName("pinger");
pinger->addTransition(new PongTransition());
QState *ponger = new QState(group);
ponger->setObjectName("ponger");
ponger->addTransition(new PingTransition());
//! [5]
//! [6]
machine.addState(group);
machine.setInitialState(group);
machine.start();
return app.exec();
}
示例3: testLoadBackupRestoreStateOnEntryExit
void HomeScreenStatePluginTest::testLoadBackupRestoreStateOnEntryExit()
{
HbInstance::instance();
HbMainWindow mainWindow;
mainWindow.show();
QCoreApplication::sendPostedEvents();
QStateMachine *sm = new QStateMachine;
HsBackupRestoreState *brs = new HsBackupRestoreState;
sm->addState(brs);
sm->setInitialState(brs);
QFinalState *fs = new QFinalState;
sm->addState(fs);
brs->addTransition(this, SIGNAL(finishStateMachine()), fs);
sm->start();
QCoreApplication::sendPostedEvents();
emit finishStateMachine();
sm->stop();
// main window deleted -> HsGui must be deleted also
delete HsGui::takeInstance();
delete sm;
}
示例4: setupItemAnimations
void DiscountPage::setupItemAnimations()
{
QState *smallState = new QState();
QState *bigState = new QState();
for (int i = 0; i < this->m_itemList.size(); i++) {
smallState->assignProperty(this->m_itemList[i],"scale", 0);
bigState->assignProperty(this->m_itemList[i],"scale",1);
}
QSequentialAnimationGroup *showItemGroup = new QSequentialAnimationGroup(this);
for (int i = 0; i < this->m_itemList.size(); i++) {
QPropertyAnimation *anim = new QPropertyAnimation(this->m_itemList[i], "scale", this);
anim->setDuration(300);
anim->setEasingCurve(QEasingCurve::OutBack);
showItemGroup->addAnimation(anim);
}
QSignalTransition *trans = smallState->addTransition(this, SIGNAL(start()), bigState);
trans->addAnimation(showItemGroup);
connect(showItemGroup,SIGNAL(finished()),this,SLOT(startSelect()));
trans = bigState->addTransition(this,SIGNAL(quitPage()),smallState);
connect(smallState,SIGNAL(entered()),this,SLOT(closeSelect()));
QStateMachine *states = new QStateMachine(this);
states->addState(smallState);
states->addState(bigState);
states->setInitialState(smallState);
states->start();
}
示例5: main
int main(int argv, char **args)
{
QApplication app(argv, args);
//![2]
QStateMachine machine;
QState *s1 = new QState();
QState *s2 = new QState();
QFinalState *done = new QFinalState();
StringTransition *t1 = new StringTransition("Hello");
t1->setTargetState(s2);
s1->addTransition(t1);
StringTransition *t2 = new StringTransition("world");
t2->setTargetState(done);
s2->addTransition(t2);
machine.addState(s1);
machine.addState(s2);
machine.addState(done);
machine.setInitialState(s1);
//![2]
//![3]
machine.postEvent(new StringEvent("Hello"));
machine.postEvent(new StringEvent("world"));
//![3]
return app.exec();
}
示例6: initShowHideAnimation
void DockPanel::initShowHideAnimation()
{
QStateMachine * machine = new QStateMachine(this);
QState * showState = new QState(machine);
showState->assignProperty(this,"y", 0);
QState * hideState = new QState(machine);
//y should change with DockMode changed
connect(this, &DockPanel::startHide, [=]{
hideState->assignProperty(this,"y", m_dockModeData->getDockHeight());
});
machine->setInitialState(showState);
QPropertyAnimation *showAnimation = new QPropertyAnimation(this, "y");
showAnimation->setDuration(SHOW_ANIMATION_DURATION);
showAnimation->setEasingCurve(SHOW_EASINGCURVE);
connect(showAnimation,&QPropertyAnimation::finished,this,&DockPanel::onShowPanelFinished);
QPropertyAnimation *hideAnimation = new QPropertyAnimation(this, "y");
hideAnimation->setDuration(HIDE_ANIMATION_DURATION);
hideAnimation->setEasingCurve(HIDE_EASINGCURVE);
connect(hideAnimation,&QPropertyAnimation::finished,this,&DockPanel::onHidePanelFinished);
QSignalTransition *st = showState->addTransition(this,SIGNAL(startHide()), hideState);
st->addAnimation(hideAnimation);
QSignalTransition *ht = hideState->addTransition(this,SIGNAL(startShow()),showState);
ht->addAnimation(showAnimation);
machine->start();
}
示例7: main
int main(int argc, char* argv[ ])
{
QApplication app(argc, argv);
QPushButton button("State Machine");
QPushButton quitButton("Quit");
QPushButton interruptButton("interrupt");
QStateMachine machine;
QState *s1 = new QState(&machine);
QState *s11 = new QState(s1);
QState *s12 = new QState(s1);
QState *s13 = new QState(s1);
s1->setInitialState(s11);
s11->assignProperty(&button, "geometry", QRect(100, 100, 100, 50));
s12->assignProperty(&button, "geometry", QRect(300, 100, 100, 50));
s13->assignProperty(&button, "geometry", QRect(200, 200, 100, 50));
QSignalTransition *transition1 = s11->addTransition(&button,
SIGNAL(clicked()), s12);
QSignalTransition *transition2 = s12->addTransition(&button,
SIGNAL(clicked()), s13);
QSignalTransition *transition3 = s13->addTransition(&button,
SIGNAL(clicked()), s11);
QPropertyAnimation *animation = new QPropertyAnimation(&button, "geometry");
transition1->addAnimation(animation);
transition2->addAnimation(animation);
transition3->addAnimation(animation);
QObject::connect(s13, SIGNAL(entered()), &button, SLOT(showMinimized()));
QFinalState *s2 = new QFinalState(&machine);
s1->addTransition(&quitButton, SIGNAL(clicked()), s2);
QObject::connect(&machine, SIGNAL(finished()), qApp, SLOT(quit()));
QHistoryState *s1h = new QHistoryState(s1);
QState *s3 = new QState(&machine);
QMessageBox mbox;
mbox.addButton(QMessageBox::Ok);
mbox.setText("Interrupted!");
mbox.setIcon(QMessageBox::Information);
QObject::connect(s3, SIGNAL(entered()), &mbox, SLOT(exec()));
s3->addTransition(s1h);
s1->addTransition(&interruptButton, SIGNAL(clicked()), s3);
machine.setInitialState(s1);
machine.start();
button.show();
quitButton.move(300, 300);
quitButton.show();
interruptButton.show();
return app.exec();
}
示例8: Foo
explicit Foo(QObject * parent = 0) :
QObject(parent),
m_state1(&m_stateMachine),
m_state2(&m_stateMachine)
{
m_stateMachine.setInitialState(&m_state1);
m_state1.addTransition(this, SIGNAL(sigGoToStateTwo()), &m_state2);
m_state2.addTransition(this, SIGNAL(sigGoToStateOne()), &m_state1);
}
示例9: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
std::random_device rd;
random_engine gen(rd());
int imageSize = 300;
QList<QImage> images;
for (int n = 0; n < 28; ++n) images << randomImage(imageSize, gen);
std::uniform_int_distribution<> dImage(0, images.size()-1);
QStackedWidget display;
QPushButton ready("I'm Ready!");
QLabel label, labelHidden;
display.addWidget(&ready);
display.addWidget(&label);
display.addWidget(&labelHidden);
QTimer splashTimer;
QStateMachine machine;
QState s1(&machine), s2(&machine), s3(&machine), s4(&machine);
splashTimer.setSingleShot(true);
QObject::connect(&s1, &QState::entered, [&]{
display.setCurrentWidget(&ready);
ready.setDefault(true);
ready.setFocus();
});
s1.addTransition(&ready, "clicked()", &s2);
QObject::connect(&s2, &QState::entered, [&]{
label.setPixmap(QPixmap::fromImage(images.at(dImage(gen))));
display.setCurrentWidget(&label);
splashTimer.start(250 + std::uniform_int_distribution<>(1500, 3000)(gen));
});
s2.addTransition(&splashTimer, "timeout()", &s3);
QObject::connect(&s3, &QState::entered, [&]{
display.setCurrentWidget(&labelHidden);
splashTimer.start(2000);
});
s3.addTransition(&splashTimer, "timeout()", &s4);
QObject::connect(&s4, &QState::entered, [&]{
display.setCurrentWidget(&label);
splashTimer.start(3000);
});
s4.addTransition(&splashTimer, "timeout()", &s1);
machine.setInitialState(&s1);
machine.start();
display.show();
return a.exec();
}
示例10: main
//! [3]
Q_DECL_EXPORT int main(int argc, char **argv)
{
Application app(argc, argv);
Factorial factorial;
// Create the state machine
QStateMachine machine;
//! [3]
//! [4]
// Create the 'compute' state as child of the state machine
QState *compute = new QState(&machine);
// Initialize the 'fac', 'x' and 'xorig' properties of the Factorial object whenever the compute state is entered
compute->assignProperty(&factorial, "fac", 1);
compute->assignProperty(&factorial, "x", 6);
compute->assignProperty(&factorial, "xorig", 6);
/**
* Add the custom transition to the compute state.
* Note: This transition has the compute state as source and target state.
*/
compute->addTransition(new FactorialLoopTransition(&factorial));
//! [4]
//! [5]
// Create a final state
QFinalState *done = new QFinalState(&machine);
// Add a custom transition with the 'compute' state as source state and the 'done' state as target state
FactorialDoneTransition *doneTransition = new FactorialDoneTransition(&factorial);
doneTransition->setTargetState(done);
compute->addTransition(doneTransition);
//! [5]
//! [6]
// Set the 'compute' state as initial state of the state machine
machine.setInitialState(compute);
// Load the UI description from main.qml
QmlDocument *qml = QmlDocument::create("asset:///main.qml");
// Make the Factorial and StateMachine object available to the UI as context properties
qml->setContextProperty("_factorial", &factorial);
qml->setContextProperty("_machine", &machine);
// Create the application scene
AbstractPane *appPage = qml->createRootObject<AbstractPane>();
Application::instance()->setScene(appPage);
return Application::exec();
}
示例11: createArrangeCollection
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void MenuStatesTest::createArrangeCollection()
{
#ifdef Q_OS_SYMBIAN
User::ResetInactivityTime();//it should help for Viewserver11 panic
#ifdef UT_MEMORY_CHECK
__UHEAP_MARK;
#endif//UT_MEMORY_CHECK
#endif//Q_OS_SYMBIAN
{
HsMenuViewBuilder builder;
HsMenuModeWrapper menuMode;
HsMainWindowMock mainWindow;
QStateMachine *machine = new QStateMachine(0);
const QString collectionName("testCollection" +
QDateTime::currentDateTime().
toString("ddmmyyyy_hh_mm_ss_zzz"));
const int collectionId = HsMenuService::createCollection(collectionName);
HsCollectionState *collectionState =
new HsCollectionState(builder, menuMode, mainWindow, machine);
collectionState->mCollectionId = collectionId;
machine->setInitialState(collectionState);
AddToHomeScreenMockState *mockState = new AddToHomeScreenMockState(machine);
// create a transition to the new child state which will be triggered by
// an event with specified operation type
HsMenuEventTransition *transition = new HsMenuEventTransition(
HsMenuEvent::ArrangeCollection, collectionState, mockState);
collectionState->addTransition(transition);
machine->start();
qApp->sendPostedEvents();
collectionState->createArrangeCollection();
qApp->sendPostedEvents();
QVERIFY(mockState->enteredValue());
qApp->removePostedEvents(0);
machine->stop();
delete machine;
}
#ifdef Q_OS_SYMBIAN
#ifdef UT_MEMORY_CHECK
__UHEAP_MARKEND;
#endif//UT_MEMORY_CHECK
#endif//Q_OS_SYMBIAN
}
示例12: Window
Window(QWidget *parent = 0)
: QWidget(parent)
{
QPushButton *button = new QPushButton(this);
button->setGeometry(QRect(100, 100, 100, 100));
//! [0]
//! [1]
QStateMachine *machine = new QStateMachine(this);
QState *s1 = new QState();
s1->assignProperty(button, "text", "Outside");
QState *s2 = new QState();
s2->assignProperty(button, "text", "Inside");
//! [1]
//! [2]
QEventTransition *enterTransition = new QEventTransition(button, QEvent::Enter);
enterTransition->setTargetState(s2);
s1->addTransition(enterTransition);
//! [2]
//! [3]
QEventTransition *leaveTransition = new QEventTransition(button, QEvent::Leave);
leaveTransition->setTargetState(s1);
s2->addTransition(leaveTransition);
//! [3]
//! [4]
QState *s3 = new QState();
s3->assignProperty(button, "text", "Pressing...");
QEventTransition *pressTransition = new QEventTransition(button, QEvent::MouseButtonPress);
pressTransition->setTargetState(s3);
s2->addTransition(pressTransition);
QEventTransition *releaseTransition = new QEventTransition(button, QEvent::MouseButtonRelease);
releaseTransition->setTargetState(s2);
s3->addTransition(releaseTransition);
//! [4]
//! [5]
machine->addState(s1);
machine->addState(s2);
machine->addState(s3);
machine->setInitialState(s1);
machine->start();
}
示例13: main
int main(int argv, char **args)
{
QApplication app(argv, args);
QStateMachine machine;
//![0]
QState *s1 = new QState();
QState *s11 = new QState(s1);
QState *s12 = new QState(s1);
QState *s13 = new QState(s1);
s1->setInitialState(s11);
machine.addState(s1);
//![0]
//![2]
s12->addTransition(quitButton, SIGNAL(clicked()), s12);
//![2]
//![1]
QFinalState *s2 = new QFinalState();
s1->addTransition(quitButton, SIGNAL(clicked()), s2);
machine.addState(s2);
machine.setInitialState(s1);
QObject::connect(&machine, SIGNAL(finished()), QApplication::instance(), SLOT(quit()));
//![1]
QButton *interruptButton = new QPushButton("Interrupt Button");
QWidget *mainWindow = new QWidget();
//![3]
QHistoryState *s1h = new QHistoryState(s1);
QState *s3 = new QState();
s3->assignProperty(label, "text", "In s3");
QMessageBox *mbox = new QMessageBox(mainWindow);
mbox->addButton(QMessageBox::Ok);
mbox->setText("Interrupted!");
mbox->setIcon(QMessageBox::Information);
QObject::connect(s3, SIGNAL(entered()), mbox, SLOT(exec()));
s3->addTransition(s1h);
machine.addState(s3);
s1->addTransition(interruptButton, SIGNAL(clicked()), s3);
//![3]
return app.exec();
}
示例14: main
int main(int argv, char **args)
{
QApplication app(argv, args);
QLabel *label = new QLabel;
//![0]
QStateMachine machine;
QState *s1 = new QState();
QState *s2 = new QState();
QState *s3 = new QState();
//![0]
//![4]
s1->assignProperty(label, "text", "In state s1");
s2->assignProperty(label, "text", "In state s2");
s3->assignProperty(label, "text", "In state s3");
//![4]
//![5]
QObject::connect(s3, SIGNAL(entered()), button, SLOT(showMaximized()));
QObject::connect(s3, SIGNAL(exited()), button, SLOT(showMinimized()));
//![5]
//![1]
s1->addTransition(button, SIGNAL(clicked()), s2);
s2->addTransition(button, SIGNAL(clicked()), s3);
s3->addTransition(button, SIGNAL(clicked()), s1);
//![1]
//![2]
machine.addState(s1);
machine.addState(s2);
machine.addState(s3);
machine.setInitialState(s1);
//![2]
//![3]
machine.start();
//![3]
label->show();
return app.exec();
}
示例15: main
//! [0]
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QPushButton button;
QStateMachine machine;
//! [0]
//! [1]
QState *off = new QState();
off->assignProperty(&button, "text", "Off");
off->setObjectName("off");
QState *on = new QState();
on->setObjectName("on");
on->assignProperty(&button, "text", "On");
//! [1]
//! [2]
off->addTransition(&button, SIGNAL(clicked()), on);
on->addTransition(&button, SIGNAL(clicked()), off);
//! [2]
//! [3]
machine.addState(off);
machine.addState(on);
//! [3]
//! [4]
machine.setInitialState(off);
machine.start();
//! [4]
//! [5]
#if defined(Q_OS_SYMBIAN)
button.showMaximized();
#elif defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR)
button.show();
#else
button.resize(100, 50);
button.show();
#endif
return app.exec();
}