Hi all;
I am tring to create a dynamic matrix of QString but I have not succed.
Are there any possibility to do it?
thanks
Hi all;
I am tring to create a dynamic matrix of QString but I have not succed.
Are there any possibility to do it?
thanks
power of mind > mind of power
Show us what you tried.
Would that do?
What it is you need it for?Qt Code:
QVector<QVecotr<QString> > stringMatrix;To copy to clipboard, switch view to plain text mode
May be what you need is a map?
Qt Code:
QVector<QVecotr<QString> > stringMatrix;To copy to clipboard, switch view to plain text mode
Qt Code:
QVector<QVector<QString> > stringMatrix;To copy to clipboard, switch view to plain text mode
power of mind > mind of power
And.... what is the problem?
I am now even able to do:Qt Code:
template <class type> class Q2DVector : public QVector< QVector<type> > { public: Q2DVector() : QVector< QVector<type> >(){}; Q2DVector(int rows, int columns) : QVector< QVector<type> >(rows) { for(int r=0; r<rows; r++) { this[r].resize(columns); } }; virtual ~Q2DVector() {}; }; typedef Q2DVector<QString> Q2DQStringVector;To copy to clipboard, switch view to plain text mode
Qt Code:
Q2DQStringVector my2DArray(4,10); my2DArray[1][5] = "thanks Robin Ericsson schrieb from qt-interest";To copy to clipboard, switch view to plain text mode
power of mind > mind of power
J-P Nurmi
I gave no 'solution', I marely made a suggestion, in trying to understand the problem.How can I (Read/Write) (from/to) element (i,j) according to your solution?
As Jpn hinted, what I suggested was a principal - which is why I asked what you need it for, since sometimes insted of string 'matrxes' string maps might be better, depending on needs.
If the principal of a 2D vector is good foryou , then making the wrapper class you got from qt-interest is trivial.
Oh, and reading/wiring to the bare QVector< QVector<QString> > is tright forword.
objs[i][j] = someString.
Resizing is offered by QVector. as you can see your self in the class you posted.
exectution failed ,debugger indicte:
power of mind > mind of power
what do you mean?exectution failed ,debugger indicte:
Segmentation fault, or compilation problem?
show your code
nothing in Q2Dvector.cppQt Code:
//Q2DVector.h #include <QVector> template <class type> class Q2DVector : public QVector< QVector<type> > { public: Q2DVector() : QVector< QVector<type> >(){}; Q2DVector(int rows, int columns) : QVector< QVector<type> >(rows) { for(int r=0; r<rows; r++) { this[r].resize(columns); } }; virtual ~Q2DVector() {}; }; typedef Q2DVector<QString> Q2DQStringVector; typedef Q2DVector<int> Q2DQIntVector;To copy to clipboard, switch view to plain text mode
Qt Code:
//main.cpp ... Q2DQStringVector myStringMatrix(P,Q); ... myStringMatrix[i][j]= someString; ...To copy to clipboard, switch view to plain text mode
I have got
Unhandled exception at 0x004244e0 in APP.exe: 0x80000001: Not implemented
Last edited by QiT; 3rd April 2007 at 15:12.
power of mind > mind of power
Oh right, you can't have a templete class that subclasses QObject.
any suggestion
power of mind > mind of power
Ok, this a "solution"
Qt Code:
//A Matrix (P,Q) sized Of QStrings QVector<QVector<QString> > myMatrixOfStrings; myMatrixOfStrings.resize(P); for(int r=0; r<P; r++) { myMatrixOfStrings[r].resize(Q); }To copy to clipboard, switch view to plain text mode
power of mind > mind of power
Yes, don't make your matrix class a template classany suggestion
Or, make your template class without inheritinig QObject (no signal slots then).
Which is what I suggested from the startOk, this a the "solution"
I think the problem is not QObject (where is it anyway? I don't see any QObjects here), but instead this:
As "this" is a pointer, you're trying to use an index operator on a pointer, which doesn't make any sense. Either use at() or dereference "this" first:
Qt Code:
(*this)[r].resize(columns);To copy to clipboard, switch view to plain text mode
QiT (4th April 2007)
Oops... you are right...I think the problem is not QObject (where is it anyway? I don't see any QObjects here),
Now I see that QVector is not a QObjet...
But I thought (obviously was wrong) that in Qt4 all cllases derived QObject.
Hmm, I better read the docs again...
Sorry about that. (wrong info).
QVector is a template class itself, so it couldn't be a QObject.
Naaa... QObject is quite heavy, so it's better to avoid it if you don't need it. Besides, you could do multiple inheritance then ("Remember, multiple inheritance is a beautiful thing!" )But I thought (obviously was wrong) that in Qt4 all cllases derived QObject.
You are right of course, didn't really think it through...QVector is a template class itself, so it couldn't be a QObject.
Bookmarks