View Single Post
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#1
I never thought I would ask this question but how to I set text to a label properly? Both of these codes just work the first time it get called.

Code:
void FoodWindow::load()
{
    QString kcal, tmp;
    QList <QString> settings;
    int remaining;
    kcal.setNum(xml->getTodaysCalories());

    settings = xml->loadSettings();
    remaining = settings.takeLast().toInt() - kcal.toInt();
    tmp.setNum(remaining);

    if(remaining >= 0)
        lblCalories->setText("You have eaten " + kcal + " kcal today (" + tmp + " left). \nYour mean kcal/day is 2800 kcal ");
    else
        lblCalories->setText("You have eaten to much today. \nYour mean kcal/day is 2800 kcal ");
}
Code:
void ExerciseWindow::loadExercise(QList<QString> name)
{
    QDBusConnection::sessionBus().send(lock);
    QList <QString> tmp;
    QList<QString> settings = xml->loadSettings();
    QString lstReps[3];
    settings.removeLast();
    SEC = settings.takeLast().toInt();
    MIN = settings.takeLast().toInt();

    currentReps = settings.takeLast();
    lstReps[2] = settings.takeLast();
    lstReps[1] = settings.takeLast();
    lstReps[0] = settings.takeLast();

    if(currentReps == "Easy")
        REPS = lstReps[0].toInt();
    else if(currentReps == "Mid")
        REPS = lstReps[1].toInt();
    else
        REPS = lstReps[2].toInt();


    SET = settings.takeLast().toInt();

    vibrateActive = false; soundActive = false;
    if(settings.takeFirst() == "1")
        vibrateActive = true;
    if(settings.takeFirst() == "1")
        soundActive = true;

    currentExercise = name.first();
    tmp = xml->openEx(currentExercise);
    tmp.removeFirst();
    currentGroup = tmp.takeFirst();

    set = SET; reps = REPS; min = MIN; sec = SEC;
    strSet.setNum(SET); strReps.setNum(REPS); strMin.setNum(MIN);  strSec.setNum(SEC);
    label->setText("");
    label->setText(currentExercise + "\n Shake when done " + strReps + " reps");
    btnShake->setEnabled(true);
    //myThread->start(QThread::NormalPriority);
}
I am able to edit the label later but not on load wich is annoying. I have printed the text using qDebug() and its correct.

I also have problem when I went from a window to a dialog. After this code is called I guess the ui is still on-top but not showing, I can push the save button again.

Code:
void NewExerciseWindow::saveExercise()
{
    QString name = txtName->text();
    QString group = btnGroup->valueText();
    QString muscle = txtMuscle->text();
    QString info = txtHowTo->toPlainText();
    if(group == "Cardio")
        xml->saveCardio(name);
    else
        xml->saveEx(name,group,muscle,info);

    QMaemo5InformationBox::information(this, "Exercise saved.",
                                                QMaemo5InformationBox::DefaultTimeout);
    this->hide();
}
Edit: Forgot two questions about QListView. How do I disable the possibility to edit in the list manually and how do I highlight a row by knowing the name?

Thanks!

Last edited by Lullen; 2010-06-17 at 00:22.