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
Printable View
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
Show us what you tried.
Would that do?
What it is you need it for?Code:
QVector<QVecotr<QString> > stringMatrix;
May be what you need is a map?
:rolleyes:Code:
QVector<QVecotr<QString> > stringMatrix;
Code:
QVector<QVector<QString> > stringMatrix;
And.... what is the problem?
I am now even able to do: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;
Code:
Q2DQStringVector my2DArray(4,10); my2DArray[1][5] = "thanks Robin Ericsson schrieb from qt-interest";
:rolleyes:
I gave no 'solution', I marely made a suggestion, in trying to understand the problem.Quote:
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:
Code:
this[r].resize(columns);
:crying:
what do you mean?Quote:
exectution failed ,debugger indicte:
Segmentation fault, or compilation problem?
show your code
nothing in Q2Dvector.cppCode:
//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;
:oCode:
//main.cpp ... Q2DQStringVector myStringMatrix(P,Q); ... myStringMatrix[i][j]= someString; ...
I have got
Unhandled exception at 0x004244e0 in APP.exe: 0x80000001: Not implemented
Oh right, you can't have a templete class that subclasses QObject.
any suggestion
http://http://www.qtcentre.org/forum...cons/icon5.gif
Ok, this a "solution"
:)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); }
Yes, don't make your matrix class a template class :)Quote:
any suggestion
Or, make your template class without inheritinig QObject (no signal slots then).
Which is what I suggested from the start ;)Quote:
Ok, 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:Code:
this[r].resize(columns);
Code:
(*this)[r].resize(columns);
Oops... you are right...Quote:
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...:rolleyes:
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!" :cool: )Quote:
But I thought (obviously was wrong) that in Qt4 all cllases derived QObject.
You are right of course, didn't really think it through... :rolleyes:Quote:
QVector is a template class itself, so it couldn't be a QObject.