Question

I'm a student programmer and I'm doing some GUI programing for my company and I have recently ran into an issue that I feel I need some assistance with. Im using Qt and some of its widgets are still confusing to me and the documentation is informative but sometimes confusing to a student(I am hoping that I'm not looking to deep into the issue and overlooking the issue). The build issue I am receiving is in the use of the Ui in the member function checkData. As you might have guessed I am trying to validate data entered into the interface and either display an error message or collect the data. I am using the toDouble function of the class QString to asses the input. The function identifies whether or not the input can be converted by the bool parameter in toDouble(bool &worksornot). Prior to the conversion toDOuble I take in the text from the lineEdit field perspectivley from the Ui. It seems that this is where my issue is; however according to the documentation this SHOULD work; however should has always been a funny word. The code for my checkData Functions is here:

void InjectionDialog::checkData()
{
        bool validateFluidVelocity;
        QString tempStrFluidVelocity;
        tempStrFluidVelocity = ui->InjectionDialog.lineEditFluidVelocity->text();
        double convertedFluidVelocity = tempStrFluidVelocity.toDouble(&validateFluidVelocity);
                if (validateFluidVelocity == false)
        {
            QErrorMessage validateErrorFluidVelocityError;
            validateErrorFluidVelocityError.showMessage("Fluid velocity input is invalid");
            validateErrorFluidVelocityError.exec();
        }
                else
                {
                    transData.lineEditFluidVelocity = convertedFluidVelocity;
                }
        bool validateFluidMassFlow;
        QString tempStrFluidMassFlow;
        tempStrFluidMassFlow = ui->InjectionDialog.lineEditFluidMassFlow->text();
        double convertedFluidMassFlow = tempStrFluidMassFlow.toDouble(&validateFluidMassFlow);
                if (validateFluidMassFlow == false)
        {
        QErrorMessage validateErrorFluidMassFlowError;
        validateErrorFluidMassFlowError.showMessage("Fluid mass flow input is invalid");
        validateErrorFluidMassFlowError.exec();
        }
                else
                {
                    transData.lineEditFluidMassFlow = convertedFluidMassFlow;
                }
        bool validateParticleVelocity;
        QString tempStrParticleVelocity;
        tempStrParticleVelocity = ui->InjectionDialog.lineEditParticleVelocity->text();
        double convertedParticleVelocity = tempStrParticleVelocity.toDouble(&validateParticleVelocity);
                if (validateParticleVelocity == false)
        {
        QErrorMessage validateErrorParticleVelocity;
        validateErrorParticleVelocity.showMessage("Particle velocity input is invalid");
        validateErrorParticleVelocity.exec();
        }
                else
                {
                    transData.lineEditParitcleVelocity =convertedParticleVelocity;
                }
        bool validateParticleMassFlow;
        QString tempStrParticleMassFlow;
        tempStrParticleMassFlow = ui->InjectionDialog.lineEditParticleMassFlow->text();
        double convertedParticleMassFlow = tempStrParticleMassFlow.toDouble(&validateParticleMassFlow);
                if (validateParticleMassFlow == false)
        {
        QErrorMessage validateErrorParticleMassFlow;
        validateErrorParticleMassFlow.showMessage("Particle mass flow input is invalid");
        validateErrorParticleMassFlow.exec();
        }
                else
                {
                    transData.lineEditParticleMassFlow = convertedParticleMassFlow;
                }

Sorry about the long names; as a student I have found that I need to use alot more description vs abbreviation. Because I'm not sure what the problem is I'm not sure how much of my code is relevant. Please don't leave negative comments or mark this question as unsubstantial. Just let me know what you would like to see and Ill add more. Heres my injectiondialog header:

#ifndef INJECTIONDIALOG_H
#define INJECTIONDIALOG_H
#include "injectiondata.h"

#include <QDialog>

namespace Ui {
class InjectionDialog;
}

class InjectionDialog : public QDialog
{
    Q_OBJECT

public:
    void setData(InjectionData &name);
    explicit InjectionDialog(QWidget *parent = 0);
    ~InjectionDialog();

private:
    InjectionData transData;
    Ui::InjectionDialog *ui;

private slots:
    void checkData();
    void checkFluidVelocity();
};

#endif // INJECTIONDIALOG_H

The exact error I recieve is invlaid use of 'Ui::InjectionDialog' and this occurs on

tempStrFluidVelocity = ui->InjectionDialog.lineEditFluidVelocity->text();
tempStrFluidMassFlow = ui->InjectionDialog.lineEditFluidMassFlow->text();
tempStrParticleVelocity = ui->InjectionDialog.lineEditParticleVelocity->text();
tempStrParticleMassFlow = ui->InjectionDialog.lineEditParticleMassFlow->text();

Thanks in advance for any help you can give me.

Was it helpful?

Solution

You only need to remove the "InjectionDialog" text and dereference the ui elements directly:

tempStrFluidVelocity = ui->lineEditFluidVelocity->text();
tempStrFluidMassFlow = ui->lineEditFluidMassFlow->text();
tempStrParticleVelocity = ui->lineEditParticleVelocity->text();
tempStrParticleMassFlow = ui->lineEditParticleMassFlow->text();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top