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. Qt Shadow build mode doesnt read txt file
Forum Updated to NodeBB v4.3 + New Features

Qt Shadow build mode doesnt read txt file

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.3k 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.
  • M Offline
    M Offline
    Marcel92
    wrote on last edited by
    #1

    Hi.
    My program reads values from a txt file and plots them in a widget.
    The normal build, without shadow build, works fine.
    If i activate the shadow build and run it with QT, the program just reads zeros.
    The strange thing is, if i run the .exe in the shadow build folder on my computer, it runs fine again.
    So the problem just occurs when i compile it with QT as a shadow build.

    Thanks in advance.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Marcel92
      wrote on last edited by
      #5

      I solved it.
      The txt file had to be in D:\Programme\QT\MeineProjekte\build-3KG-Desktop_Qt_5_8_0_MinGW_32bit-Debug
      Not in D:\Programme\QT\MeineProjekte\build-3KG-Desktop_Qt_5_8_0_MinGW_32bit-Debug\debug !!

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi
        Sounds like you read from fixed path ?
        So when using shadow , it cannot find file.
        The reading zero part, sounds like the variable is just empty as nothing was read.

        But i'm only guessing.

        Shadow build just change the folder where the .exe is produced.
        Could be anything.

        You should show some code. How you open the text file etc.

        1 Reply Last reply
        2
        • M Offline
          M Offline
          Marcel92
          wrote on last edited by
          #3
          vector<double> EKG2File::createEKGVector(int counterLine)
            {
          
              counterLine--;
              fstream readFile;
              readFile.open("EKGData.txt", ios::in); ////////////////!!!!
              vector<double> aGUI(7);
          
              int countBuf = counterLine;
          
          
                for (size_t i = 0; i <countBuf; i++)
                {
                  readFile >> counterLine >> lA >> lL >> rA;
                }
          
          
              //Überspringen der bereits gelesenen Zeilen
          
              //Hochzählen für nächstes Mal
              //Erstellen des Vektors für die aktuelle Zeile
              readFile >> counterLine >> lA >> lL >> rA;
              EKG2File::berechneAbl(lA, lL, rA);
          
              std::cout << counterLine <<" "<< lA <<" "<< lL <<" "<< rA << '\n';
              //std::cout << counterLine <<" "<< abl1 <<" "<< abl2 <<" "<< abl3 << " " << aVL << " " << aVR << " " << aVF << '\n';
          
              aGUI[0]=counterLine;
              aGUI[1]=abl1;
              aGUI[2]=abl2;
              aGUI[3]=abl3;
              aGUI[4]=aVR;
              aGUI[5]=aVL;
              aGUI[6]=aVF;
          
              closeFile();
              return (aGUI);
            };
          
          QVector<double> x,abl1,abl2,abl3;
              vector<double> plotVector(7);
          
              graph_erstellen();
          
              do
              {
                  QApplication::processEvents();
                  //Stopp-Bedingung
                  if(stoppVariable == 0)
                  {
                      graph_zuruecksetzen();
                      break;
                  }
          
                  plotVector = werteVector.createEKGVector(i);///////////
                  x.append(plotVector[0]);
                  abl1.append(plotVector[1]);
                  abl2.append(plotVector[2]);
                  abl3.append(plotVector[3]);
          
                  ui->Plot1->graph(0)->setData(x,abl1);
                  ui->Plot1->replot();
          
                  ui->Plot2->graph(0)->setData(x,abl2);
                  ui->Plot2->replot();
                  ui->Plot3->graph(0)->setData(x,abl3);
                  ui->Plot3->replot();
          

          here is some code.The first part is the function to open the file and write the values in a vector.
          The second part is how i use these values, if you want to see that.
          I think the main problem is that he cant find the file.
          But as i said, the strange thing is, that he finds the file when i run the .exe in the shadow folder.
          I´ll write some code and look if Qt opens the file correctly.

          Thanks for your answer.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Marcel92
            wrote on last edited by
            #4

            Ok, so i tried it with the direct path of the txt file and it works now.
            is there another way to open it in the current directory?
            i tried different options, like "./EKGData.txt" but it doesnt work.
            Whereas in the normal build this way (((readFile.open("EKGData.txt", ios::in); )))) works fine.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Marcel92
              wrote on last edited by
              #5

              I solved it.
              The txt file had to be in D:\Programme\QT\MeineProjekte\build-3KG-Desktop_Qt_5_8_0_MinGW_32bit-Debug
              Not in D:\Programme\QT\MeineProjekte\build-3KG-Desktop_Qt_5_8_0_MinGW_32bit-Debug\debug !!

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #6

                Hi
                Good found.
                I normally use

                readFile.open(qApp->applicationDirPath()+"/"+"EKGData.txt", ios::in)

                Which means where exe is.

                This saves me for issues in case something change the current active path for the application
                and open("nopathfilename.txt" will fail.

                1 Reply Last reply
                2

                • Login

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