Skip to content

Commit 40900f4

Browse files
committed
Update event loop docs
1 parent e7e9bba commit 40900f4

File tree

1 file changed

+2
-36
lines changed

1 file changed

+2
-36
lines changed

docs/Getting started.md

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,5 @@ int main(int argc, char **argv) {
2424
The \link libscratchcpp::Project::run() run() \endlink method runs an event loop which stops after all scripts finish.
2525
2626
For CLI project players, using \link libscratchcpp::Project::run() run() \endlink is enough. If you are developing
27-
a GUI project player and need to receive input events such as key presses, you'll need to implement your own event loop
28-
or use the one provided by the GUI framework.
29-
30-
## GUI example (Qt)
31-
Qt provides an event loop which can be easily used to run frames with a specific frame rate.
32-
33-
For example, a `Player` class which **inherits from QObject** can use a timer:
34-
```cpp
35-
#include <QObject>
36-
#include <scratchcpp/project.h>
37-
38-
class Player : public QObject {
39-
Q_OBJECT
40-
public:
41-
Player(QObject *parent = nullptr);
42-
Player(const Player &) = delete; // Project is not copyable
43-
44-
protected:
45-
void timerEvent(QTimerEvent *event) override;
46-
47-
private:
48-
libscratchcpp::Project m_proj;
49-
}
50-
51-
Player::Player(QObject *parent) {
52-
m_proj.setFileName("/path/to/project.sb3");
53-
m_proj.start();
54-
int fps = 30;
55-
startTimer(1000.0 / fps);
56-
}
57-
58-
void Player::timerEvent(QTimerEvent *event) {
59-
m_proj.frame();
60-
event->accept();
61-
}
62-
```
27+
a GUI project player and need to receive input events such as key presses, you'll need to use \link libscratchcpp::Project::runEventLoop() runEventLoop() \endlink
28+
and run it in another thread (to keep the UI responsive).

0 commit comments

Comments
 (0)