2 Replies Latest reply on Mar 30, 2017 10:18 PM by patilpralhad

    Not able to add multiple dictionary entries for art

    patilpralhad Level 1

      Hello,

       

       

      I'm trying to set a dictionary entry on art object which is internally a set of multiple dictionary entries.

      What is happening is, I'm able to set only 1 entry on object.

      always my container dictionary entry size remains 1. Not sure, why is this. Please suggest me if I'm doing anything wrong.

       

       

      Here's code

       

       

      .

      .

      .

      sAIArt->GetDictionary(artHandle,&artDictRef);

      AIDictionaryRef containerDictionaryRef = NULL;

      sAIDictionary->CreateDictionary(&containerDictionaryRef);

      foreach (const QJsonValue & v, array)

      {

       

        QString id = v.toObject().value("eachElementKey").toString();

       

        AIDictionaryRef eachElementRef = NULL;

        sAIDictionary->CreateDictionary(&eachElementRef);

        sAIDictionary->SetStringEntry(eachElementRef,eachElementKey,id.toStdString().c_str());

        sAIDictionary->SetDictEntry(containerDictionaryRef,AIDictKey(QString::number(index++)).to StdString().c_str()),eachElementRef);

        int dictionarySize = sAIDictionary->Size(containerDictionaryRef);

        AlertUtil::alert("size of dictionary is ",QString::number(dictionarySize)); // always returns 1.

        sAIDictionary->Release(eachElementRef);

      }

      sAIDictionary->SetDictEntry(artDictRef,AIDictKey("containerKey"),containerDictionaryRef);

       

       

      sAIDictionary->Release(containerDictionaryRef);

      sAIDictionary->Release(artDictRef);

      .

      .

      .

       

      Regards,

      Pralhad

        • 1. Re: Not able to add multiple dictionary entries for art
          A. Patterson Level 4

          Well, it sounds like you're doing something wrong with the entry name for dictionaries being added to the container dictionary. Can you tell if the single entry you end up with is always the last one you created? If so, that would seem to indicate that you're setting the same entry over and over, and you should look closely at the dictionary key you're generating.

           

          On that note, I'm not 100% sure you can use a straight up number as your entry name. That may be allowed, but it seems odd to me. When I do this kind of thing, I usually name it something like 'entry1', 'entry2', etc.. You're using Qt, so it'd be pretty easy to get that by using arg():

           

          sAIDictionary->SetDictEntry(containerDictionaryRef,AIDictKey(QString("entry%1").arg(index++)).to StdString().c_str()),eachElementRef);

           

          I'd try building the entry name into a stand alone variable so you can debug and see what it looks like before it gets passed to the SetDictEntry() call. I suspect you'll find that somehow, it's not changing the way you want it to.

          • 2. Re: Not able to add multiple dictionary entries for art
            patilpralhad Level 1

            Thanks for your reply Patterson,

            I've checked each entry with alert box. It was different.

             

            Problem was while creating Key.

             

            AIDictKey key = sAIDictionary->Key("keyName");

            sAIDictionary->SetStringEntry(artDictRef,key,"value");

             

            Changing code to like I'm doing above worked for me.

             

            And you're right about the Key entry creation part. I'm exactly doing what you explained. Thanks for mentioning that.

             

            Regards,

            Pralhad