【问题标题】:Convert 2D vector to 2D QVector C++将二维向量转换为二维 QVector C++
【发布时间】:2014-12-02 07:23:44
【问题描述】:

我目前正在使用 C++ 开发一个项目,我正在使用 Visual Studio 2010 Express 和 Qt Creator 5.3.2。用于应用程序的 GUI。

我的问题是我想将 2D 矢量转换为 2D QVector,但我真的不知道该怎么做。例如,我使用 fromStdVector() 将 1D 矢量转换为 1D QVector,但我无法成功地将数据从 2D 矢量传输到 2D QVector(使用此函数)。如果有人可以提供帮助,我将不胜感激。

源代码:

QVector< QVector<double> > test2D; // 2D QVector
vector < vector<double> >  std_test2D; // 2D vector

test2D.resize(20); // dimensions of the 2D QVector
for(int i=0; i<20; ++i)
{
  test2D[i].resize(44);
}

std_test2D.resize(20); // dimensions of the 2D vector
for(int i=0; i<20; ++i)
{
  std_test2D[i].resize(44);
}

for(int i=0; i<20; i++)  // convert vector to QVector???
{
    test2D[i].fromStdVector(std_test2D[i]);
}

【问题讨论】:

    标签: c++ visual-studio qt vector qvector


    【解决方案1】:

    您没有分配值。我认为这应该使用example code from the documentation:

     test2D[i] = QVector<double>::fromStdVector(std_test2D[i]);
    

    【讨论】:

      【解决方案2】:

      您可以尝试以下方法:

      for(int i = 0; i < 20; i++)
      {
          QVector v = QVector<double>::fromStdVector(std_test2D[i]);
          test2D[i].push_back(v);
      }
      

      【讨论】:

        猜你喜欢
        • 2021-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-26
        • 2021-02-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多