このページでは

QQueue Class

template <typename T> class QQueue

QQueue クラスは、キューを提供するジェネリックコンテナです。詳細...

ヘッダー: #include <QQueue>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
継承元: QList

注:このクラスのすべての関数は再入可能です。

パブリック関数

T dequeue()
void enqueue(T &&t)
void enqueue(const T &t)
T &head()
const T &head() const
void swap(QQueue<T> &other)

詳細な説明

QQueue<T> は Qt のジェネリックコンテナクラスの 1 つであり、T は要素の型を指定します。これは、同じ型の項目に対するキューデータ構造を実装しています。

キューは、先入れ先出し(FIFO)の構造です。アイテムは、enqueue() を使用してキューの末尾に追加され、dequeue() を使用して先頭から取得されます。head() 関数を使用すると、先頭のアイテムを削除せずにアクセスすることができます。

例:

QQueue<int> queue;
queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);
while (!queue.isEmpty())
    cout << queue.dequeue() << endl;

この例では、1、2、3の順に出力されます。

QQueueはQList を継承しています。QList の機能はすべてQQueueにも適用されます。たとえば、isEmpty()を使用してキューが空かどうかを判定したり、QList のイテレータクラス(例:QListIterator )を使用してQQueueを走査したりすることができます。 さらに、QQueue には FIFO セマンティクスを簡単に実装できる 3 つの便利な関数が用意されています。enqueue()、dequeue()、およびhead() です。

QQueueの値型は、代入可能なデータ型でなければなりません。これにより、一般的に使用されるほとんどのデータ型がカバーされますが、例えば、QWidget を値として格納することはコンパイラによって許可されません。その場合は、代わりにQWidget*を使用してください。

「 QList 」および「QStack 」も参照してください 。

メンバ関数のドキュメント

T QQueue::dequeue()

キューの先頭にある要素を取り出し、それを返します。この関数は、キューが空ではないことを前提としています。

これは `QList::takeFirst()` と同じ動作です。

head()、enqueue()、およびisEmpty()も参照してください 。

void QQueue::enqueue(T &&t)

void QQueue::enqueue(const T &t)

キューの末尾に値t を追加します。

これは `QList::append()` と同じ動作です。

dequeue() およびhead()も参照してください 。

キューの先頭要素への参照を返します。この関数は、キューが空ではないことを前提としています。

これは `QList::first()` と同様です。

dequeue()、enqueue()、およびisEmpty()も参照してください 。

const T &QQueue::head() const

これはオーバーロードされた関数です。

[noexcept] void QQueue::swap(QQueue<T> &other)

このキューとother を交換します。この操作は非常に高速で、失敗することはありません。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.