1

私はメインのQtアプリケーションを持っており、このメインアプリケーションからリンクするQtライブラリを開発しています。メインアプリケーションから、何かを実行するライブラリ内の関数を呼び出し、ルーチンの最後にQTimerを呼び出して、少し遅れてライブラリコードのスロットを起動します。タイマーを作動させることができず、理由がわかりません。メインアプリにタイマーを配置すると、ライブラリではなく、期待どおりにタイマーが起動します。

今のところ、私のライブラリは1つのクラスにすぎません。ライブラリヘッダーファイルで、呼び出したいスロットを次のように定義します。

private slots:

        void stop();

実装ファイルには次のようなものがあります。

    void MyLib::start() {

        // Create a timer to user during audio operation
        m_GeneralTimer = new QTimer(this);

        // Fire off a oneshot to clear the buffer for fluke-media
        m_GeneralTimer->setInterval(3000);
        m_GeneralTimer->setSingleShot(true);
        connect(m_GeneralTimer, SIGNAL(timeout()), SLOT(stop()));
        m_GeneralTimer->start();
    }
    void MyLib::stop() {

        qDebug() << "Called stop()...";
        m_GeneralTimer->stop();
        delete m_GeneralTimer;
    }

タイマーが作動するためにここで何が欠けていますか?

注:これが私のヘッダーファイルの多くです-実際のファイルでこれ以降はすべて関数呼び出しです:

/// Use shared memory
#include <QSharedMemory>

/// Normal Qt Includes
#include <QBuffer>
#include <QDebug>

/// QTimer is required for calling a method
/// to stop audio playback at a later time
#include <QTimer>

/// Put into a background thread
#include <QtConcurrentRun>

/// Check integrity of received data
#include <QCryptographicHash>

class MYAUDIOLIBSHARED_EXPORT MyLib: public QObject
{

    Q_OBJECT

    public:

            /// /// ///

    private slots:

            void stop();

            /// /// ///
}
4

1 に答える 1

1

次のコードは機能します。start()関数に3秒入れたところ、ライブラリ呼び出しから起動しました。

    // Create a timer to fire a slot when the playback is done
    m_EndPlayBackTimer = new QTimer(this);
    m_EndPlayBackTimer->setInterval(3000);
    m_EndPlayBackTimer->setSingleShot(true);
    connect(m_EndPlayBackTimer, SIGNAL(timeout()), SLOT(playBackDone()));
    m_EndPlayBackTimer->start(3000);

    // Done
    return;

}

/**
 * @brief
 * Slot to be started by a timer after some time delay
 * to signify that the playback is complete.
 *
 */
void MyLib::playBackDone() {

    #if DEBUG
    qDebug() << "Playback is complete...";
    #endif

}
于 2013-03-25T19:49:35.217 に答える