Does not open file in Qt

  • Hi!
    I'm trying to open and read an .obj file but i am unable to do so.
    My code is
    0_1512208577863_Captura de pantalla 2017-12-02 a las 10.53.35.png
    My problem is that in the first If it returns false and I don't know why.
    My file is in the .qrc and also in the path ("Users/carolina/unchocolatito2").
    If someone could help it would be great

  • Lifetime Qt Champion

    Are you sure path is correct ?

    I feel it should be "/Users/carolina/unchocolatito2"

  • Hi! Thank you for replying me. I have changed what you said but it still doesn't work.

  • Lifetime Qt Champion

    Ok not sure what linux you are on, my Users folder is called home

    If you open shell
    and do
    cd /Users/carolina/unchocolatito2
    does that work? ( meaning it change to there)

    If you put file in a qres file. then find file in Creator, and right click it. You can
    the copy path.

    alt text

    And use that ":/xxxx" path where you have todojuntolabio.obj now

  • Thank you so much. My computer is a macOs but I just did what you said about copying the path and now it works.
    Now I have this problem.
    0_1512212995342_Captura de pantalla 2017-12-02 a las 12.07.36.png
    When I try to click in qvector.h it says that the file doesn't exist or I don't have permission

  • Lifetime Qt Champion

    It says you are using a where xxx is larger than the numbers of items in the list
    (or list is empty )

    Can you paste the code ? ( the image only shows top of it)
    ( you can just use the </> button in editor and paste the real code )

  • @mrjj here it is

    void QObj3dReader::parseObjFile(const QString &fileName,
                                    QStringList &comments,
                                    QVector<QOpenGLTriangle3D> &triangles)
        QFile file(fileName);
            if( | QFile::Text))
                QVector<QVector3D> v, vn;
                 qDebug() << "se abre";
                    QString line = file.readLine().trimmed();
                    QStringList lineParts = line.split(QRegularExpression("\\s+"));
                    if(lineParts.count() > 0)
                        // if it's a comment
                        if("#", Qt::CaseInsensitive) == 0)
                            comments.append(line.remove(0, 1).trimmed());
                        // if it's a vertex position (v)
                        else if("v", Qt::CaseInsensitive) == 0)
                        // if it's face data (f)
                        // there's an assumption here that faces are all triangles
                        else if("f", Qt::CaseInsensitive) == 0)
                            QOpenGLTriangle3D triangle;
                            // get points from v array
                            triangle.p1 ="/").at(0).toInt() - 1);
                            triangle.p2 ="/").at(0).toInt() - 1);
                            triangle.p3 ="/").at(0).toInt() - 1);
                            // get normals from vn array
                            triangle.p1Normal ="/").at(2).toInt() - 1);
                            triangle.p2Normal ="/").at(2).toInt() - 1);
                            triangle.p3Normal ="/").at(2).toInt() - 1);

  • Lifetime Qt Champion

    From a quick look
    It dont seem you append anything to the vn vector and then later do
    triangle.p1Normal =

    alt text

    So its empty and u try to get element.

  • Thank you so much!!
    I was trying different ways to try to open a file that doing copy and paste I forgot some lines of the code. Now it works.

  • Lifetime Qt Champion

    Super :)
    Notice that
    lines such at"/").at(2)
    will give same kind of error if format is different and split returns an empty list.

Log in to reply

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