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. QFile Readall return empty array only in Release build
Forum Updated to NodeBB v4.3 + New Features

QFile Readall return empty array only in Release build

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 936 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
    Charlez Kwan
    wrote on last edited by Charlez Kwan
    #1

    Hi all,
    I recently building an Qt application using Qtwebengine, which I want to run the javascript from an external javascript library in the QRC resources, I am able to read it and load it into the Qtwebengine in the Debug build, but when i switched to the Release build, it returns empty.

    Here is my code:

     QFile file;
      QString filejs;
      file.setFileName(":/res/web/file.js");
      file.open(QIODevice::ReadOnly);
      filejs = file.readAll();
      ui->webView->page()->runJavaScript(QString(filejs));
    

    I tried to print out the file js after readAll(), it is empty only in Release build.
    Does anyone know why?

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

      Hi
      Could you try to see if file is actually there ?

      QDirIterator it(":", QDirIterator::Subdirectories);
      while (it.hasNext()) {
      qDebug() << it.next();
      }

      also does file.open(..) report ok or not ?

      C 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        Could you try to see if file is actually there ?

        QDirIterator it(":", QDirIterator::Subdirectories);
        while (it.hasNext()) {
        qDebug() << it.next();
        }

        also does file.open(..) report ok or not ?

        C Offline
        C Offline
        Charlez Kwan
        wrote on last edited by
        #3

        @mrjj said in QFile Readall return empty array only in Release build:

        Hi
        Could you try to see if file is actually there ?

        QDirIterator it(":", QDirIterator::Subdirectories);
        while (it.hasNext()) {
        qDebug() << it.next();
        }

        also does file.open(..) report ok or not ?

        The file is actually there.
        file.exist() or file.open() also report fine
        The Iterator also log all the files and they are present.

        I found out in the release build and the debug build they have different named .o files, don't know if it is because the build setting cause the application can't find the file.
        Is there any way to correct address a resource file in qrc for file reading?

        mrjjM 1 Reply Last reply
        0
        • C Charlez Kwan

          @mrjj said in QFile Readall return empty array only in Release build:

          Hi
          Could you try to see if file is actually there ?

          QDirIterator it(":", QDirIterator::Subdirectories);
          while (it.hasNext()) {
          qDebug() << it.next();
          }

          also does file.open(..) report ok or not ?

          The file is actually there.
          file.exist() or file.open() also report fine
          The Iterator also log all the files and they are present.

          I found out in the release build and the debug build they have different named .o files, don't know if it is because the build setting cause the application can't find the file.
          Is there any way to correct address a resource file in qrc for file reading?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Charlez-Kwan
          That is very odd.
          the syntax is the way
          ":/res/web/file.js"

          what does file.size() return ?

          also

          • different named .o
            For your files or what has ?
          C 1 Reply Last reply
          0
          • mrjjM mrjj

            @Charlez-Kwan
            That is very odd.
            the syntax is the way
            ":/res/web/file.js"

            what does file.size() return ?

            also

            • different named .o
              For your files or what has ?
            C Offline
            C Offline
            Charlez Kwan
            wrote on last edited by
            #5

            @mrjj said in QFile Readall return empty array only in Release build:

            @Charlez-Kwan
            That is very odd.
            the syntax is the way
            ":/res/web/file.js"

            what does file.size() return ?

            also

            • different named .o
              For your files or what has ?

            File.size() return 0 is release build, return the correct value in debug build.
            in debug build, theres qrc_web.o /.cpp , but not in release build
            in release build theres res_web_file_js.o/.cpp

            mrjjM 1 Reply Last reply
            0
            • C Charlez Kwan

              @mrjj said in QFile Readall return empty array only in Release build:

              @Charlez-Kwan
              That is very odd.
              the syntax is the way
              ":/res/web/file.js"

              what does file.size() return ?

              also

              • different named .o
                For your files or what has ?

              File.size() return 0 is release build, return the correct value in debug build.
              in debug build, theres qrc_web.o /.cpp , but not in release build
              in release build theres res_web_file_js.o/.cpp

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Charlez-Kwan

              Ok so there is nothing it just name it seems in the release.

              ok that is odd with the file names. Does it do that for other file ?
              Also is other file also size 0 ?

              Maybe its not actually linked in even i never saw that before.

              C 1 Reply Last reply
              0
              • mrjjM mrjj

                @Charlez-Kwan

                Ok so there is nothing it just name it seems in the release.

                ok that is odd with the file names. Does it do that for other file ?
                Also is other file also size 0 ?

                Maybe its not actually linked in even i never saw that before.

                C Offline
                C Offline
                Charlez Kwan
                wrote on last edited by
                #7

                @mrjj said in QFile Readall return empty array only in Release build:

                @Charlez-Kwan

                Ok so there is nothing it just name it seems in the release.

                ok that is odd with the file names. Does it do that for other file ?
                Also is other file also size 0 ?

                Maybe its not actually linked in even i never saw that before.

                I deactivated the Qt-quick compiler in the release build option and it works fine now.

                mrjjM 1 Reply Last reply
                1
                • C Charlez Kwan

                  @mrjj said in QFile Readall return empty array only in Release build:

                  @Charlez-Kwan

                  Ok so there is nothing it just name it seems in the release.

                  ok that is odd with the file names. Does it do that for other file ?
                  Also is other file also size 0 ?

                  Maybe its not actually linked in even i never saw that before.

                  I deactivated the Qt-quick compiler in the release build option and it works fine now.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Charlez-Kwan
                  aha! maybe it likes js files in another way when Release mode.
                  Good found :)

                  C 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @Charlez-Kwan
                    aha! maybe it likes js files in another way when Release mode.
                    Good found :)

                    C Offline
                    C Offline
                    Charlez Kwan
                    wrote on last edited by
                    #9

                    @mrjj said in QFile Readall return empty array only in Release build:

                    @Charlez-Kwan
                    aha! maybe it likes js files in another way when Release mode.
                    Good found :)

                    @mrjj
                    yes, i thought it must be some project setting because it works in debug build completely fine.
                    Thank you for your help!

                    mrjjM 1 Reply Last reply
                    1
                    • C Charlez Kwan

                      @mrjj said in QFile Readall return empty array only in Release build:

                      @Charlez-Kwan
                      aha! maybe it likes js files in another way when Release mode.
                      Good found :)

                      @mrjj
                      yes, i thought it must be some project setting because it works in debug build completely fine.
                      Thank you for your help!

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Charlez-Kwan
                      Np :)
                      Thank you for reporting back.
                      When someday someone else experiences this, this should help.

                      1 Reply Last reply
                      0

                      • Login

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