Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Does not open file in Qt
Forum Updated to NodeBB v4.3 + New Features

Does not open file in Qt

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Carolinabustillo
    wrote on 2 Dec 2017, 09:59 last edited by
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 2 Dec 2017, 10:21 last edited by mrjj 12 Feb 2017, 10:22
      #2

      Hi
      Are you sure path is correct ?

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

      1 Reply Last reply
      2
      • C Offline
        C Offline
        Carolinabustillo
        wrote on 2 Dec 2017, 10:29 last edited by
        #3

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

        M 1 Reply Last reply 2 Dec 2017, 10:37
        1
        • C Carolinabustillo
          2 Dec 2017, 10:29

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

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 2 Dec 2017, 10:37 last edited by mrjj 12 Feb 2017, 10:47
          #4

          @Carolinabustillo
          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

          1 Reply Last reply
          3
          • C Offline
            C Offline
            Carolinabustillo
            wrote on 2 Dec 2017, 11:13 last edited by
            #5

            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

            M 1 Reply Last reply 2 Dec 2017, 11:16
            0
            • C Carolinabustillo
              2 Dec 2017, 11:13

              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

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 2 Dec 2017, 11:16 last edited by mrjj 12 Feb 2017, 11:18
              #6

              @Carolinabustillo
              Hi
              It says you are using a vector.at(XXX) 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 )

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Carolinabustillo
                wrote on 2 Dec 2017, 11:21 last edited by
                #7

                @mrjj here it is

                void QObj3dReader::parseObjFile(const QString &fileName,
                                                QStringList &comments,
                                                QVector<QOpenGLTriangle3D> &triangles)
                {
                    comments.clear();
                    triangles.clear();
                
                    QFile file(fileName);
                    if(file.exists())
                    {
                        if(file.open(QFile::ReadOnly | QFile::Text))
                        {
                            QVector<QVector3D> v, vn;
                             qDebug() << "se abre";
                
                            while(!file.atEnd())
                            {
                                QString line = file.readLine().trimmed();
                                QStringList lineParts = line.split(QRegularExpression("\\s+"));
                                if(lineParts.count() > 0)
                                {
                
                                    // if it's a comment
                                    if(lineParts.at(0).compare("#", Qt::CaseInsensitive) == 0)
                                    {
                                        comments.append(line.remove(0, 1).trimmed());
                                    }
                
                                    // if it's a vertex position (v)
                                    else if(lineParts.at(0).compare("v", Qt::CaseInsensitive) == 0)
                                    {
                                        v.append(QVector3D(lineParts.at(1).toFloat(),
                                                           lineParts.at(2).toFloat(),
                                                           lineParts.at(3).toFloat()));
                                    }
                
                
                
                                    // if it's face data (f)
                                    // there's an assumption here that faces are all triangles
                                    else if(lineParts.at(0).compare("f", Qt::CaseInsensitive) == 0)
                                    {
                                        QOpenGLTriangle3D triangle;
                
                                        // get points from v array
                                        triangle.p1 = v.at(lineParts.at(1).split("/").at(0).toInt() - 1);
                                        triangle.p2 = v.at(lineParts.at(2).split("/").at(0).toInt() - 1);
                                        triangle.p3 = v.at(lineParts.at(3).split("/").at(0).toInt() - 1);
                
                
                
                                        // get normals from vn array
                                        triangle.p1Normal = vn.at(lineParts.at(1).split("/").at(2).toInt() - 1);
                                        triangle.p2Normal = vn.at(lineParts.at(2).split("/").at(2).toInt() - 1);
                                        triangle.p3Normal = vn.at(lineParts.at(3).split("/").at(2).toInt() - 1);
                
                                        triangles.append(triangle);
                                    }
                
                                }
                            }
                
                            file.close();
                        }
                    }
                }
                
                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 2 Dec 2017, 11:28 last edited by mrjj 12 Feb 2017, 11:33
                  #8

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

                  alt text

                  So its empty and u try to get element.

                  1 Reply Last reply
                  3
                  • C Offline
                    C Offline
                    Carolinabustillo
                    wrote on 2 Dec 2017, 11:34 last edited by
                    #9

                    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.

                    M 1 Reply Last reply 2 Dec 2017, 11:38
                    0
                    • C Carolinabustillo
                      2 Dec 2017, 11:34

                      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.

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 2 Dec 2017, 11:38 last edited by mrjj 12 Feb 2017, 11:41
                      #10

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

                      1 Reply Last reply
                      0

                      1/10

                      2 Dec 2017, 09:59

                      • Login

                      • Login or register to search.
                      1 out of 10
                      • First post
                        1/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved