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(const T &t)
T &head()
const T &head() const
void swap(QQueue<T> &other)

詳細説明

QQueue<T> は Qt の汎用コンテナクラスの一つです。同じ型のアイテムのためのキューデータ構造を実装しています。

キューは先入れ先出し(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(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 と入れ替える。この操作は非常に高速で、失敗することはない。

© 2025 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.