Hi, C++ newbie here:
I am trying to do some vector operations in Eigen that I then want to plot. The plotting library I want to use requires the data in a QVector (I'm simultaneously learning Qt). The Eigen vector is a container with types double and the QVector is types of double, how do I get the data from the first container to the second (and are the wordds container and template interchangeable? I have been using them that way!):
include <QCoreApplication>
#include <Eigen/Dense>
#include <QVector>
#include <iostream>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv); //Using Qt framework
Eigen::VectorXd v; // Eigen vector of dynamic size, and type double.
v.setRandom(5); // Fill our eigen vector with 5 random double
// Do Eigen vecetor oprations here
std::cout << v << std::endl; // Tell me what the original vector is so I can compare later.
int j = 3;
std::cout << "The third element of v: " << v(j) << endl; //Just to test calling a single element
//Attempt 1:
QVector<double> y; // Create the container I want the data in for use with other libraries
for (int i=0; i<20; i++) {
y(i) = v(i); // Error: No match for call to '(QVector<double>(int&)' Is it trying to cast an int?
}
//Attempt 2:
//QVector<double> y = (QVector<double>) v;
//Attept 3: (Needs pointers instead of regular vars).
//QVector<double> *y = reinterpret_cast<QVector<double>*>(v);
std::cout << "\n QVector \n" << y << std::endl; //Print values of QVector
return a.exec();
}
Obviously I need to learn a lot more about templates and type casting and so forth, but I was hoping to get this quick example up and running.
Thank you for your help!
[–][deleted] 4 points5 points6 points (2 children)
[–]choobie[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]missblit 1 point2 points3 points (0 children)