本页内容

QGenericMatrix Class

template <int N, int M, typename T> class QGenericMatrix

QGenericMatrix 类是一个模板类,表示一个具有 N 列和 M 行的 N×M 变换矩阵。更多内容...

头文件: #include <QGenericMatrix>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui

公共函数

QGenericMatrix()
QGenericMatrix(const T *values)
const T *constData() const
void copyDataTo(T *values) const
T *data()
const T *data() const
void fill(T value)
bool isIdentity() const
void setToIdentity()
QGenericMatrix<M, N, T> transposed() const
bool operator!=(const QGenericMatrix<N, M, T> &other) const
T &operator()(int row, int column)
const T &operator()(int row, int column) const
QGenericMatrix<N, M, T> &operator*=(T factor)
QGenericMatrix<N, M, T> &operator+=(const QGenericMatrix<N, M, T> &other)
QGenericMatrix<N, M, T> &operator-=(const QGenericMatrix<N, M, T> &other)
QGenericMatrix<N, M, T> &operator/=(T divisor)
bool operator==(const QGenericMatrix<N, M, T> &other) const
QMatrix2x2
QMatrix2x3
QMatrix2x4
QMatrix3x2
QMatrix3x3
QMatrix3x4
QMatrix4x2
QMatrix4x3
QGenericMatrix<N, M, T> operator*(T factor, const QGenericMatrix<N, M, T> &matrix)
QGenericMatrix<N, M, T> operator*(const QGenericMatrix<N, M, T> &matrix, T factor)
QGenericMatrix<M1, M2, TT> operator*(const QGenericMatrix<NN, M2, TT> &m1, const QGenericMatrix<M1, NN, TT> &m2)
QGenericMatrix<N, M, T> operator+(const QGenericMatrix<N, M, T> &m1, const QGenericMatrix<N, M, T> &m2)
QGenericMatrix<N, M, T> operator-(const QGenericMatrix<N, M, T> &m1, const QGenericMatrix<N, M, T> &m2)
QGenericMatrix<N, M, T> operator-(const QGenericMatrix<N, M, T> &matrix)
QGenericMatrix<N, M, T> operator/(const QGenericMatrix<N, M, T> &matrix, T divisor)
QDataStream &operator<<(QDataStream &stream, const QGenericMatrix<N, M, T> &matrix)
QDataStream &operator>>(QDataStream &stream, QGenericMatrix<N, M, T> &matrix)

详细说明

QGenericMatrix<N, M, T> 是一个模板类,其中N 表示列数,M 表示行数,T 表示该类的用户可见的元素类型。

另请参阅 QMatrix4x4 。

成员函数文档

QGenericMatrix::QGenericMatrix()

构建一个N ×M 的单位矩阵。

[explicit] QGenericMatrix::QGenericMatrix(const T *values)

根据给定的N *M 浮点数values 构建一个矩阵。假设数组values 的内容按行优先顺序排列。

另请参阅 copyDataTo()。

const T *QGenericMatrix::constData() const

返回指向该矩阵原始数据的常量指针。

另请参阅 data()。

void QGenericMatrix::copyDataTo(T *values) const

检索该矩阵中N *M 的元素,并按行优先顺序将其复制到values 中。

T *QGenericMatrix::data()

返回指向该矩阵原始数据的指针。

另请参阅 constData()。

const T *QGenericMatrix::data() const

返回指向该矩阵原始数据的常量指针。

另请参阅 constData()。

void QGenericMatrix::fill(T value)

将该矩阵的所有元素填充为value 。

bool QGenericMatrix::isIdentity() const

如果该矩阵是单位矩阵,则返回true ;否则返回false。

另请参阅 setToIdentity()。

void QGenericMatrix::setToIdentity()

将该矩阵设置为单位矩阵。

另请参阅 isIdentity()。

QGenericMatrix<M, N, T> QGenericMatrix::transposed() const

返回该矩阵,并将其沿对角线转置。

bool QGenericMatrix::operator!=(const QGenericMatrix<N, M, T> &other) const

如果该矩阵与other 不相同,则返回true ;否则返回false。

T &QGenericMatrix::operator()(int row, int column)

返回该矩阵中位于位置 (row,column) 的元素的引用,以便可以向该元素赋值。

const T &QGenericMatrix::operator()(int row, int column) const

返回对该矩阵中位于位置 (row,column) 的元素的常量引用。

QGenericMatrix<N, M, T> &QGenericMatrix::operator*=(T factor)

将该矩阵的所有元素与factor 相乘。

QGenericMatrix<N, M, T> &QGenericMatrix::operator+=(const QGenericMatrix<N, M, T> &other)

将other 中的内容添加到该矩阵中。

QGenericMatrix<N, M, T> &QGenericMatrix::operator-=(const QGenericMatrix<N, M, T> &other)

从该矩阵中减去other 的元素。

QGenericMatrix<N, M, T> &QGenericMatrix::operator/=(T divisor)

将该矩阵的所有元素除以divisor 。

bool QGenericMatrix::operator==(const QGenericMatrix<N, M, T> &other) const

如果该矩阵与other 完全相同,则返回true ;否则返回 false。

相关非成员

QMatrix2x2

QMatrix2x2 类型定义了QGenericMatrix 模板的一个便捷实例化形式,该实例具有 2 列、2 行,且元素类型为 float。

QMatrix2x3

QMatrix2x3 类型定义了QGenericMatrix 模板的一个便捷实例化形式,该实例具有 2 列、3 行,且元素类型为 float。

QMatrix2x4

QMatrix2x4 类型定义了QGenericMatrix 模板的一个便捷实例化形式,该实例具有 2 列、4 行,且元素类型为 float。

QMatrix3x2

QMatrix3x2 类型定义了QGenericMatrix 模板的一个便捷实例化形式,该实例具有 3 列、2 行,且元素类型为 float。

QMatrix3x3

QMatrix3x3 类型定义了QGenericMatrix 模板的一个便捷实例化形式,适用于 3 列、3 行且元素类型为 float 的情况。

QMatrix3x4

QMatrix3x4 类型定义了QGenericMatrix 模板的一个便捷实例化形式,该实例具有 3 列、4 行,且元素类型为 float。

QMatrix4x2

QMatrix4x2 类型定义了QGenericMatrix 模板的一个便捷实例化形式,该实例具有 4 列、2 行,且元素类型为 float。

QMatrix4x3

QMatrix4x3 类型定义了QGenericMatrix 模板的一个便捷实例化形式,该实例具有 4 列、3 行,且元素类型为 float。

template < int N, int M, typename T > QGenericMatrix<N, M, T> operator*(T factor, const QGenericMatrix<N, M, T> &matrix)

返回将N xM matrix 中的所有元素与factor 相乘的结果。

template < int N, int M, typename T > QGenericMatrix<N, M, T> operator*(const QGenericMatrix<N, M, T> &matrix, T factor)

返回将matrix 中的所有元素与factor 相乘的结果。

template < int NN, int M1, int M2, typename TT > QGenericMatrix<M1, M2, TT> operator*(const QGenericMatrix<NN, M2, TT> &m1, const QGenericMatrix<M1, NN, TT> &m2)

返回NN ×M2 矩阵m1 与M1 ×NN 矩阵m2 的乘积,从而生成一个M1 ×M2 矩阵的结果。

template < int N, int M, typename T > QGenericMatrix<N, M, T> operator+(const QGenericMatrix<N, M, T> &m1, const QGenericMatrix<N, M, T> &m2)

返回矩阵m1 和m2 的和,其中N ×M 。

template < int N, int M, typename T > QGenericMatrix<N, M, T> operator-(const QGenericMatrix<N, M, T> &m1, const QGenericMatrix<N, M, T> &m2)

返回N ×M 矩阵m1 和m2 之间的差值。

template < int N, int M, typename T > QGenericMatrix<N, M, T> operator-(const QGenericMatrix<N, M, T> &matrix)

返回matrix 的取反。

这是一个重载函数。

template < int N, int M, typename T > QGenericMatrix<N, M, T> operator/(const QGenericMatrix<N, M, T> &matrix, T divisor)

返回将N xM matrix 中的所有元素除以divisor 所得的结果。

template < int N, int M, typename T > QDataStream &operator<<(QDataStream &stream, const QGenericMatrix<N, M, T> &matrix)

将给定的N xM matrix 写入给定的stream ,并返回该流的引用。

另请参阅 《Qt 数据类型的序列化》。

template < int N, int M, typename T > QDataStream &operator>>(QDataStream &stream, QGenericMatrix<N, M, T> &matrix)

从给定的stream 中读取一个N ×M 的矩阵,将其写入给定的matrix ,并返回该流的引用。

另请参阅 《Qt 数据类型的序列化》。

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