QString Result from QSettings



  • Hi

    The problem I'm having is when reading back String variables from a .conf file, only the first String read is valid, then the following String reads are not returning the Pre-Written string.

    Here is the Read Function: -

    @//***********************************************************************************************************
    //
    // Function : ReadRecipes
    //
    // Passed : void
    // Returns : bool
    //
    // Reads the programmed recipe information from disk.
    //***********************************************************************************************************
    bool MainWindow::ReadRecipes()
    {
    TRecipeStruct *CurrentRecipe;
    TRecipeStruct *LastRecipe;
    unsigned int RecipeCount;
    unsigned int RecipeMax;
    QString RecipeCountStr;
    QString TmpString;

    RecipeCount = 0;
    RecipeMax = 0;
    QSettings Recipes("Anmar","Recipes");
    Recipes.sync();
    Recipes.beginGroup("RecipeCount");
    RecipeMax = Recipes.value("Count",0).toInt();
    Recipes.endGroup();
    while (RecipeCount < RecipeMax)
    {
        RecipeCount++;
        qApp->processEvents();
        CurrentRecipe = new TRecipeStruct();
        if (CurrentRecipe)
        {
            Recipes.beginGroup("RecipeNames");
            RecipeCountStr = "Recipe" + QString::number(RecipeCount);
            TmpString = Recipes.value(RecipeCountStr,"BlankName").toByteArray();
            CurrentRecipe->RecipeName = TmpString;
            Recipes.endGroup();
            Recipes.beginGroup(CurrentRecipe->RecipeName);
            CurrentRecipe->FlourWeight = Recipes.value("FlourWeight").toFloat();
            CurrentRecipe->SiloPercentage[0] = Recipes.value("Silo1Percent").toFloat();
            CurrentRecipe->SiloPercentage[1] = Recipes.value("Silo2Percent").toFloat();
            CurrentRecipe->SiloPercentage[2] = Recipes.value("Silo3Percent").toFloat();
            CurrentRecipe->SiloPercentage[3] = Recipes.value("Silo4Percent").toFloat();
            CurrentRecipe->WaterPercentage = Recipes.value("WaterPerecentage").toFloat();
            CurrentRecipe->DoughTemp = Recipes.value("DoughTemp").toFloat();
            CurrentRecipe->MixerTime = Recipes.value("Mixer1Time").toInt();
            CurrentRecipe->MixerConstant = Recipes.value("MixerConst1").toFloat();
            if (!SystemSetup->Recipes)
            {
                SystemSetup->Recipes = CurrentRecipe;
                CurrentRecipe->Prev = 0;
                CurrentRecipe->Next = 0;
            }
            else
            {
                LastRecipe = SystemSetup->Recipes;
                while(LastRecipe->Next)
                {
                    LastRecipe = LastRecipe->Next;
                    qApp->processEvents();
                }
                LastRecipe->Next = CurrentRecipe;
                CurrentRecipe->Prev = LastRecipe;
                CurrentRecipe->Next = 0;
            }
        }
    }
    return true;
    

    }@

    An example .conf file.

    @[RecipeCount]
    Count=3

    [RecipeNames]
    Recipe1=Test1
    Recipe2=Test2
    Recipe3=Test3

    [Test1]
    DoughTemp=@Variant(\0\0\0\x87\x41\xe4\0\0)
    FlourWeight=@Variant(\0\0\0\x87\0\0\0\0)
    Mixer1Time=0
    MixerConst1=@Variant(\0\0\0\x87\0\0\0\0)
    Silo1Percent=@Variant(\0\0\0\x87\0\0\0\0)
    Silo2Percent=@Variant(\0\0\0\x87\0\0\0\0)
    Silo3Percent=@Variant(\0\0\0\x87\0\0\0\0)
    Silo4Percent=@Variant(\0\0\0\x87\0\0\0\0)
    WaterPercent=@Variant(\0\0\0\x87\0\0\0\0)

    [Test2]
    DoughTemp=@Variant(\0\0\0\x87\x41\xe4\0\0)
    FlourWeight=@Variant(\0\0\0\x87\0\0\0\0)
    Mixer1Time=0
    MixerConst1=@Variant(\0\0\0\x87\0\0\0\0)
    Silo1Percent=@Variant(\0\0\0\x87\0\0\0\0)
    Silo2Percent=@Variant(\0\0\0\x87\0\0\0\0)
    Silo3Percent=@Variant(\0\0\0\x87\0\0\0\0)
    Silo4Percent=@Variant(\0\0\0\x87\0\0\0\0)
    WaterPercent=@Variant(\0\0\0\x87\0\0\0\0)

    [Test3]
    DoughTemp=@Variant(\0\0\0\x87\x41\xe4\0\0)
    FlourWeight=@Variant(\0\0\0\x87\0\0\0\0)
    Mixer1Time=0
    MixerConst1=@Variant(\0\0\0\x87\0\0\0\0)
    Silo1Percent=@Variant(\0\0\0\x87\0\0\0\0)
    Silo2Percent=@Variant(\0\0\0\x87\0\0\0\0)
    Silo3Percent=@Variant(\0\0\0\x87\0\0\0\0)
    Silo4Percent=@Variant(\0\0\0\x87\0\0\0\0)
    WaterPercent=@Variant(\0\0\0\x87\0\0\0\0)@

    With the above code, on first scan, recipe "Test1" is valid, whereas the next 2 the result returned from QSettings->value is the "BlankName" default result. Without a default value, "" is returned.



  • I have the same result with either

    TmpString = Recipes.value(RecipeCountStr,"BlankName").toByteArray();

    or

    TmpString = Recipes.value(RecipeCountStr,"BlankName").toString();



  • In your code I don't see closing endGroup() for
    @
    Recipes.beginGroup(CurrentRecipe->RecipeName);
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.