Results 1 to 8 of 8

Thread: Accessing QList Objects

  1. #1
    Join Date
    Sep 2006
    Posts
    15
    Thanks
    2

    Default Accessing QList Objects

    I could use some help....

    I am trying to access a 2 dimensional array of QList objects. What it is a QVariantList (which is actually a typedef in QVariant as a QList<QVariant>) passed into another QList<QVariantList> to form a 2 dimensional array. The original QVariantList has a blank character array of 100 chars so the QList is a 2 dimensional array of chars. Or at least it is supposed to be (I can't get passed the error so I haven't been able to check).

    Why would I ever want to do something so complicated? Well if you really want to know, I am trying to use a stored procedure in an Oracle database that calls for a 2d array of chars as one of the parameters. I am composing an update of existing technology to change it into the newer QT environment. I'm essentially trying to convert ProC (if you have ever heard of that language) to C++.

    So now on to the question. I have passed the 2d QList into the stored procedure and now I am trying to get into the QList to retrieve the data. The code I tried below doesn't seem to work. HELP!!! In advance, I thank you.

    --Normal C++ 2D Array--
    char sIntAlignZone [100][2];

    --QList Version--
    QVariantList charArray;
    for(int i = 0; i < 100; i++)
    charArray << QVariant(QVariant::ByteArray);
    QList<QVariantList> sIntAlignZone;
    for(int j = 0; j < 2; j++)
    sIntAlignZone << charArray;

    --After Stored Procedure--
    dataP->alignZone = sIntAlignZone[i][0];

    --Compile Error--
    FitcheckDB.cpp(691) : error C2440: '=' : cannot convert from 'QVariant' to 'char'

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Accessing QList Objects

    Do you really need QVariant here? If you just want a 2D array of chars constant size, why not use char[][]? Or QVarLengthArray< QVarLengthArray< QChar > > if you insist on using Qt types.

  3. #3
    Join Date
    Sep 2006
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Accessing QList Objects

    Quote Originally Posted by wysota View Post
    Do you really need QVariant here? If you just want a 2D array of chars constant size, why not use char[][]? Or QVarLengthArray< QVarLengthArray< QChar > > if you insist on using Qt types.
    I would agree with the above; However, the reason for the compile problem is that it can't automatically convert a QVariant (passed back from sIntAlignZone[x][y]) to a char.



    To do the conversion, you'd have to do an explicit conversion along the lines of this:

    Qt Code:
    1. QChar theQChar = sIntAlignZone[x][y].toChar();
    2. char myChar = theQChar.unicode();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Accessing QList Objects

    But the question remains -- what do you need QVariant for?

  5. #5
    Join Date
    Sep 2006
    Posts
    15
    Thanks
    2

    Default Re: Accessing QList Objects

    The reason for a QVariant is because in order to use a stored procedure via QSqlQuery and binding values you need to pass in a QVariant of some sort.

    I'm going to try the QChar way but keep replying if it doesn't work. Thanks everyone.

  6. #6
    Join Date
    Sep 2006
    Posts
    15
    Thanks
    2

    Default Re: Accessing QList Objects

    I attempted this but I believe the way that a QList << call is structured so that the QVariantLists are on top of each other and not side by side...

    --I'm attempting to make this--
    char sActWBS [100][2];

    //First of all I make a QVariantList filled with 100 chars
    QVariantList charArray;
    for(int i = 0; i < 100; i++)
    charArray << QVariant(QVariant::Char);

    //Then I put 10 of the charArray lists into another QList
    QList<QVariantList> sActWBS;
    for(int j = 0; j < 10; j++)
    sActWBS << charArray;


    Do you think this will work like a 2d array?

    If so, how do I parse the array once I am finished, starting with the first column then the second and so on.

    If not, I know that I could write a function to manipulate the data like a 2d array if my assumption is correct and the QVariantLists are on top of each other but this doesn't satisfy the stored procedure parameter that I need (a 2d char array).

    I didn't realize that this was going to be so complicated. If anyone has a better idea of how to make a 2d char array using QVariant I am all ears. Before submitting it, make sure that a BindValue function parameter in QSqlQuery will support the idea. It needs a QVariant object to be passed into it to work properly.

    Thank you again.

  7. #7
    Join Date
    Sep 2006
    Posts
    15
    Thanks
    2

    Default Re: Accessing QList Objects

    Can anyone think of another way to implement a 2d char array into a 2d array of QVariants for a BindValue function parameter in QSqlQuery to accept???

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Accessing QList Objects

    Maybe you could use QVector instead of QList? And if not, why not provide your own serialisation of data and go directly for QByteArray which can be stored in QVariant?

Similar Threads

  1. Replies: 7
    Last Post: 18th July 2006, 21:33
  2. accessing form1's objects from form2
    By Philip_Anselmo in forum Newbie
    Replies: 5
    Last Post: 4th May 2006, 22:54
  3. Values not being appended in a QList
    By Kapil in forum Newbie
    Replies: 5
    Last Post: 21st April 2006, 10:20
  4. Accessing objects in different forms
    By Lebowski in forum Newbie
    Replies: 17
    Last Post: 13th April 2006, 11:20
  5. Help me to use QtSharedMemory to share the data objects
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 11:50

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.