I have to pass a 2d array of Strings to a function in another class.
How should I do it? If u cannot help me with code, then at least point to the articles i should read to learn how to achieve this...
I have to pass a 2d array of Strings to a function in another class.
How should I do it? If u cannot help me with code, then at least point to the articles i should read to learn how to achieve this...
You could pass somethin like:
Qt Code:
QVector<QStringList> 2dStringArr;To copy to clipboard, switch view to plain text mode
http://lmgtfy.com/?q=C%2B%2B+2d+array+as+argumentIf u cannot help me with code, then at least point to the articles i should read to learn how to achieve this...
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Simple code - You've got here 2D array of int, I think it looks similary with strings (maybe You should use QString and QStringList instead strings?):
Qt Code:
void show(int **tab2D,int howManyRows,int howManyCols) { for (int i=0;i<howManyRows;i++) { for (int j=0;j<howManyCols;j++) cout<<tab2D[i][j]<<" "; cout<<endl;; } } int main(int argc, char* argv[]) { int **tab; int k,w ; cin>>w; cin>>k; tab=new int * [w]; for (int i=0;i<w;i++) tab[i]=new int[k]; for (int i=0;i<w;i++) for (int j=0;j<k;j++) tab[i][j]=random(100); show(tab,w,k); for (int i=0;i<w;i++) delete [] tab[i]; delete [] tab; return 0; }To copy to clipboard, switch view to plain text mode
best regards
Tomasz
Thanks for answers, but now i need to pass back a bunch of widgets, how do i do that?
Well, the same way.
Use QVector, its the same principal.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Thanks for your answers, but could u, please, explain what should i do with that QVector<QString> 2dStringArray?
Could u, please, tell me how to call the function, and what parameter should be in that function to represent this QVector?
No QVector<QString> but QVector<QStringList>:
Qt Code:
QVector<QStringList> vector(10); vector[0].append("aaa"); vector[0].append("bbb");To copy to clipboard, switch view to plain text mode
In vector[0][1] You have "bbb". The same thing You can do with other rows (vector[0..9]).
best regards
Tomasz
Archa4 (7th February 2011)
This thread slowly is getting off topic, since your questions are going in the direction of basic C/C++ concepts and syntax.
I will answer this but please be sure to understand basic C/C++ syntax and concepts before asking further questions.
I suggested QVector<QStringList>, and not QVector<QString>explain what should i do with that QVector<QString> 2dStringArray?
Be sure to read both classes descriptions to understand the difference.
This is your 2D array of strings.
Have a look at the QVector docs to understand what it is doing.
This is your first dimension, its a "list" of "string lists".
QStringList is a list of strings.
By having a vector of QStrigLists you have a 2D array of strings.
A method declaration that takes this array could look something like:
Qt Code:
void my2DFunc(const QVector<QStringList> &my2DArray) { //lets iterate: for(int i=0; my2DArray.size(); i++){ //Do something with the string list. } }To copy to clipboard, switch view to plain text mode
Last edited by high_flyer; 7th February 2011 at 14:43. Reason: typo
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Archa4 (7th February 2011)
Bookmarks