Home > database >  Qt c data from XML String not being displayed properly in QTableView after parsing
Qt c data from XML String not being displayed properly in QTableView after parsing

Time:08-29

I have almost finished the Output1

If I alter the program so that ContainerView is a QTextEdit instead of a QTableView (I did this to troubleshoot so I know which values are not getting assigned a value), and then use the following code instead:

...
                        while(!Box_Info.isNull())
                        {
                            if(Box_Info.tagName() == "Code")
                            {
                                BCode = Box_Info.text();
                                ContainerView->append("Box Code: "   BCode);
                            }
                            if(Box_Info.tagName() == "Height")
                            {
                                BH = Box_Info.text().toInt(nullptr,10);
                                ContainerView->append("Box Height: "   QString::number(BH));
                            }
                            etc.
...

Then I get the following output:
Output2

CodePudding user response:

Thanks for the Comment, Scheff's Cat.

My mistake was indeed in the Add_to_CV function.

It should have been:

void MainWindow::Add_to_CV(QString C, QString Con, int Pn, int Bh, int Bb, int Bl, int Bw)
{
    QList<QStandardItem*> row;
    QStandardItem *Pallet_Num_Item = new QStandardItem(QString::number(Pn));
    QStandardItem *Container_Type = new QStandardItem(Con);
    QStandardItem *Box_Code = new QStandardItem(C);
    QStandardItem *Box_Height = new QStandardItem(QString::number(Bh));
    QStandardItem *Box_Breadth = new QStandardItem(QString::number(Bb));
    QStandardItem *Box_Length = new QStandardItem(QString::number(Bl));
    QStandardItem *Box_Weight = new QStandardItem(QString::number(Bw));
    row << Pallet_Num_Item << Container_Type << Box_Code << Box_Height << Box_Breadth << Box_Length << Box_Weight;
    HMod->appendRow(row);
}

void MainWindow::Add_to_CV(QString C, QString Con, int Pn, int Ch, int Cd, int Cw)
{
    QList<QStandardItem*> row;
    QStandardItem *Pallet_Num_Item = new QStandardItem(QString::number(Pn));
    QStandardItem *Container_Type = new QStandardItem(Con);
    QStandardItem *Cylinder_Code = new QStandardItem(C);
    QStandardItem *Cylinder_Height = new QStandardItem(QString::number(Ch));
    QStandardItem *Cylinder_Diameter = new QStandardItem(QString::number(Cd));
    QStandardItem *Cylinder_Blank = new QStandardItem(" "); //Cylinder does not have a Length
    QStandardItem *Cylinder_Weight = new QStandardItem(QString::number(Cw));
    row <<Pallet_Num_Item << Container_Type << Cylinder_Code << Cylinder_Height << Cylinder_Diameter << Cylinder_Blank << Cylinder_Weight;
    HMod->appendRow(row);
}

When initializing the QStandardItem's, it needed to instantiate them using an QString. I had them being initialized using an int.

Thanks for the help.

  • Related