Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting an integer from a vector

    Customer c = data.getCustomer(index.row());
    QString assetId = QString::fromStdString(c.getAssetId());
    QString name = QString::fromStdString(c.getName());
    QString price = QString::fromStdString(c.getPrice());
    QString quantity = QString::fromStdString(c.getQuantity());
    QString category = QString::fromStdString(c.getCategory());
    QString roomNumber = QString::fromStdString(c.getRoomNumber());

I am trying to get an integer from assetId, price, quantity, roomNumber.

I’m unsure what syntax to use to get the int from Qstring.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use toInt member function of QString class

QString str = "10";
int i = str.toInt(); // now i is 10.

If you need to check if conversion was successful, you can also use additional bool to indicate success.

QString str = "not a number";
bool success;
int i = str.toInt(&success); // success is false, because conversion failed, i holds value 0. 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading