答案代码位于此处(/sf/answers/3538533001/):
https://github.com/eyllanesc/stackoverflow/tree/master/50550089
答案比下面的代码更简单 - 上面的代码使用 QPropertyAnimation 而不是像下面这样使用带有 QThread 的 for 循环 - 这节省了代码中的大量空间并且效率更高。
原问题如下:
我正在用 Qt 编写应用程序,但在关闭应用程序和线程时遇到问题。
基本上,应用程序窗口会关闭,但该进程仍保留在后台并且永远不会关闭。
我的主要标题(因为有很多包含,所以只包含了这个类):
class ChatUI : public QWidget
{
Q_OBJECT
public:
explicit ChatUI(QWidget *parent = 0);
~ChatUI();
private:
// The UI itself
Ui::ChatUI * ui;
// Current appliation startup directory
QString applicationStartupDir = QDir::currentPath() + "/";
// Typing indicator stuff
QFrame * typingIndicator = nullptr;
QImage circleImage;
ThreadController * typingIndicatorThread = new ThreadController(false);
bool currentlyFadingTypingIndicator = false;
// The calm before the …Run Code Online (Sandbox Code Playgroud)