Results 1 to 20 of 20

Thread: dynamic matrix of QStrings

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default dynamic matrix of QStrings

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: dynamic matrix of QStrings

    Show us what you tried.
    Would that do?
    Qt Code:
    1. QVector<QVecotr<QString> > stringMatrix;
    To copy to clipboard, switch view to plain text mode 
    What it is you need it for?
    May be what you need is a map?

  3. #3
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: dynamic matrix of QStrings

    Qt Code:
    1. QVector<QVecotr<QString> > stringMatrix;
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. QVector<QVector<QString> > stringMatrix;
    To copy to clipboard, switch view to plain text mode 
    power of mind > mind of power

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: dynamic matrix of QStrings

    And.... what is the problem?

  5. #5
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: dynamic matrix of QStrings

    Quote Originally Posted by high_flyer View Post
    And.... what is the problem?
    How can I (Read/Write) (from/to) element (i,j) according to your solution?
    Last edited by QiT; 3rd April 2007 at 14:05.
    power of mind > mind of power

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: dynamic matrix of QStrings

    Quote Originally Posted by QiT View Post
    How can I acced to element (i,j) according to your solution?
    In exactly the same way. The spoon-fed Q2DQStringVector is just a template wrapper around the same underlying data structure suggested by high_flyer with the only difference being the one additional convenience method for resizing the vectors.
    J-P Nurmi

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: dynamic matrix of QStrings

    How can I (Read/Write) (from/to) element (i,j) according to your solution?
    I gave no 'solution', I marely made a suggestion, in trying to understand the problem.
    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.

  8. #8
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: dynamic matrix of QStrings

    exectution failed ,debugger indicte:

    Qt Code:
    1. this[r].resize(columns);
    To copy to clipboard, switch view to plain text mode 

    power of mind > mind of power

  9. #9
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: dynamic matrix of QStrings

    exectution failed ,debugger indicte:
    what do you mean?
    Segmentation fault, or compilation problem?
    show your code

  10. #10
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: dynamic matrix of QStrings

    Qt Code:
    1. //Q2DVector.h
    2. #include <QVector>
    3.  
    4. template <class type>
    5. class Q2DVector : public QVector< QVector<type> >
    6. {
    7.  
    8. public:
    9. Q2DVector() : QVector< QVector<type> >(){};
    10. Q2DVector(int rows, int columns) : QVector< QVector<type> >(rows) {
    11. for(int r=0; r<rows; r++) {
    12. this[r].resize(columns);
    13. }
    14. };
    15. virtual ~Q2DVector() {};
    16. };
    17. typedef Q2DVector<QString> Q2DQStringVector;
    18. typedef Q2DVector<int> Q2DQIntVector;
    To copy to clipboard, switch view to plain text mode 
    nothing in Q2Dvector.cpp
    Qt Code:
    1. //main.cpp
    2.  
    3. ...
    4. Q2DQStringVector myStringMatrix(P,Q);
    5. ...
    6. myStringMatrix[i][j]= someString;
    7. ...
    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

  11. #11
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: dynamic matrix of QStrings

    Oh right, you can't have a templete class that subclasses QObject.

  12. #12
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: dynamic matrix of QStrings

    any suggestion
    power of mind > mind of power

  13. #13
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: dynamic matrix of QStrings

    Qt Code:
    1. template <class type>
    2. class Q2DVector : public QVector< QVector<type> >
    3. {
    4. public:
    5. Q2DVector() : QVector< QVector<type> >(){};
    6. Q2DVector(int rows, int columns) : QVector< QVector<type> >(rows) {
    7. for(int r=0; r<rows; r++) {
    8. this[r].resize(columns);
    9. }
    10. };
    11. virtual ~Q2DVector() {};
    12. };
    13. typedef Q2DVector<QString> Q2DQStringVector;
    To copy to clipboard, switch view to plain text mode 
    I am now even able to do:
    Qt Code:
    1. Q2DQStringVector my2DArray(4,10);
    2. 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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.