Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User Acemaker's Avatar
    Join Date
    Jul 2007
    Posts
    4
    I can't find a solution to read one Item from CDesCArray *itemList.

    Here is one method what i've tried, but result is KERN-EXEC 3 in the if- statement.

    Is there anyone there who can help me find a better working solution.


    My Code:


    void CDialogQueryAppView::SetDialogTest(){

    TInt index( 0 );
    CAknListQueryDialog* dlg = new( ELeave ) CAknListQueryDialog( &index );

    // construct listbox item array
    CDesCArray* itemList = new (ELeave) CDesCArrayFlat(3);

    _LIT( KFirst, "1st Item" );
    _LIT( KSecond, "2nd Item" );
    _LIT( KThird, "3rd Item" );

    HBufC* item = HBufC::NewL(20);

    *item = KFirst;
    itemList->AppendL(*item);
    *item = KSecond;
    itemList->AppendL(*item);
    *item = KThird;
    itemList->AppendL(*item);

    dlg->PrepareLC( R_AVKON_LIST_QUERY );
    dlg->SetItemTextArray( itemList );

    if( dlg->RunLD()){
    // ok pressed, index is the selected item index.

    *item = (*itemList)[index];
    iEikonEnv->InfoMsg( *item );
    }
    delete item;
    }

    -Desperately seeking

  2. #2
    Regular Contributor cdavies's Avatar
    Join Date
    May 2007
    Posts
    463
    It isn't a pointer array, the CDesCArray in to which it'll copy the strings you store. If you want a copy on the heap of the selected item after the dialog has completed, you code should look something like this:

    CDesCArray* itemList = new (ELeave) CDesCArrayFlat(3);

    _LIT( KFirst, "1st Item" );
    _LIT( KSecond, "2nd Item" );
    _LIT( KThird, "3rd Item" );

    itemList->AppendL(KFirst);
    itemList->AppendL(KSecond);
    itemList->AppendL(KThird);

    dlg->PrepareLC( R_AVKON_LIST_QUERY );
    dlg->SetItemTextArray( itemList );

    if( dlg->RunLD()){
    // ok pressed, index is the selected item index.

    HBufC* selectedItem = (*itemList)[index].AllocL();
    iEikonEnv->InfoMsg( *selectedItem );

    You could also do:
    iEikonEnv->InfoMsg((*itemList)[index]);

    To get the same result.
    Get Resolvr - The Zeroconf framework for Symbian OS free today. Make your IP networking applications fun and easy to use. http://www.novelinteractions.com/resolvr/
    Proud to be the only autorickshaw owner in Cambridge - http://blog.novelinteractions.com/images/tuktuk.jpg

  3. #3
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Mallorca, Holiday
    Posts
    27,683
    You can try if SetOwnershipType(ELbmDoesNotOwnItemArray) helps. KERN-EXEC 3 may happen because the dialog simply resets and deletes your descriptor array.

  4. #4
    Registered User Acemaker's Avatar
    Join Date
    Jul 2007
    Posts
    4
    Thanks for your helpiing answers.

    Now it works with "SetOwnershipType(ELbmDoesNotOwnItemArray)", but i still got App.Closed Alloc:xxxxxxx message, when I use OK-softkey ( if- statement in code), and then close the application.


    So this code works and reads from CDesCArray:


    void CDialogQueryAppView::SetDialogTest(){

    TInt index( 0 );
    CAknListQueryDialog* dlg = new( ELeave ) CAknListQueryDialog( &index );

    // construct listbox item array
    CDesCArray* itemList = new (ELeave) CDesCArrayFlat(3);

    _LIT( KFirst, "1st Item" );
    _LIT( KSecond, "2nd Item" );
    _LIT( KThird, "3rd Item" );

    itemList->AppendL(KFirst);
    itemList->AppendL(KSecond);
    itemList->AppendL(KThird);

    dlg->PrepareLC( R_AVKON_LIST_QUERY );
    dlg->SetItemTextArray( itemList );
    dlg->SetOwnershipType( ELbmDoesNotOwnItemArray );

    if( dlg->RunLD()){
    // ok pressed, index is the selected item index.
    HBufC *selectedItem = HBufC::NewL(20);
    selectedItem = (*itemList)[index].AllocL();
    iEikonEnv->InfoMsg( *selectedItem );
    delete selectedItem;
    }
    }

  5. #5
    Regular Contributor cdavies's Avatar
    Join Date
    May 2007
    Posts
    463
    With your new code, you're leaking the array and the redundant HBufC you create. Your code should go something like this:

    CDesCArray* itemList = new (ELeave) CDesCArrayFlat(3);
    CleanupStack::PushL(itemList);

    _LIT( KFirst, "1st Item" );
    _LIT( KSecond, "2nd Item" );
    _LIT( KThird, "3rd Item" );

    itemList->AppendL(KFirst);
    itemList->AppendL(KSecond);
    itemList->AppendL(KThird);
    dlg->PrepareLC( R_AVKON_LIST_QUERY );
    dlg->SetItemTextArray( itemList );
    dlg->SetOwnershipType( ELbmDoesNotOwnItemArray );

    if( dlg->RunLD()){
    // ok pressed, index is the selected item index.
    HBufC* selectedItem = (*itemList)[index].AllocL(); /* This line creates a new HBufC, no need to create one first. */
    iEikonEnv->InfoMsg( *selectedItem );
    delete selectedItem;
    }

    CleanupStack::PopAndDestroy(itemList);
    Get Resolvr - The Zeroconf framework for Symbian OS free today. Make your IP networking applications fun and easy to use. http://www.novelinteractions.com/resolvr/
    Proud to be the only autorickshaw owner in Cambridge - http://blog.novelinteractions.com/images/tuktuk.jpg

  6. #6
    Registered User Acemaker's Avatar
    Join Date
    Jul 2007
    Posts
    4
    Thanks.

    SolvedAndClosed();

    Too much buffers today.

  7. #7
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Mallorca, Holiday
    Posts
    27,683
    A slight addition: if you have the array containing descriptors, it is not that important to allocate one of them separately on the heap.
    Code:
    if(dlg->RunLD()){
        iEikonEnv->InfoMsg((*itemList)[index]);
    }
    should work.

Similar Threads

  1. ListBox item numbers not updating
    By sriramadasu in forum Symbian C++
    Replies: 1
    Last Post: 2006-10-29, 00:01
  2. Problem : Activate Listbox Item
    By Nierdre in forum Symbian User Interface
    Replies: 3
    Last Post: 2004-12-18, 20:28
  3. Single listbox item update?
    By mayur_24 in forum Symbian C++
    Replies: 1
    Last Post: 2004-12-03, 01:45
  4. ListBox icon array
    By Gingah in forum Symbian User Interface
    Replies: 9
    Last Post: 2004-10-14, 11:37
  5. listbox item height...
    By yahyah_yy in forum Symbian C++
    Replies: 0
    Last Post: 2004-04-05, 18:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved