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. QCoreApplication console application does not output with Valgrind
Forum Updated to NodeBB v4.3 + New Features

QCoreApplication console application does not output with Valgrind

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 481 Views
  • 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.
  • GuerrianG Offline
    GuerrianG Offline
    Guerrian
    wrote on last edited by Guerrian
    #1

    I have a QCoreApplication console application which works fine if I run it normally, but when I run it with "Analyze -> Valgrind Memory Analyzer", there is no output after "hi":

    Runner::Runner(QCoreApplication *parent)
    {
        app = parent;
    }
    
    void Runner::run()
    {
        cout << "hi" << endl;
        QCommandLineParser parser;
        parser.setApplicationDescription("Description...");
        parser.addHelpOption();
        cout << "does not output here" << endl;
        app->quit();
    }
    
    int main(int argc, char *argv[])
    {
        QCoreApplication app(argc, argv);
        Runner *runner = new Runner(&app);
        QTimer::singleShot(0, runner, SLOT(run()));
        return app.exec();
    }
    

    Linux Mint 18.3
    Qt 5.14.1
    Qt Creator 4.11.1

    KroMignonK 1 Reply Last reply
    0
    • GuerrianG Guerrian

      I have a QCoreApplication console application which works fine if I run it normally, but when I run it with "Analyze -> Valgrind Memory Analyzer", there is no output after "hi":

      Runner::Runner(QCoreApplication *parent)
      {
          app = parent;
      }
      
      void Runner::run()
      {
          cout << "hi" << endl;
          QCommandLineParser parser;
          parser.setApplicationDescription("Description...");
          parser.addHelpOption();
          cout << "does not output here" << endl;
          app->quit();
      }
      
      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
          Runner *runner = new Runner(&app);
          QTimer::singleShot(0, runner, SLOT(run()));
          return app.exec();
      }
      
      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @Guerrian QCommandLineParser should be place in main()!

      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
      
          QCommandLineParser parser;
          parser.setApplicationDescription("Description...");
          parser.addHelpOption();
      
          parser.process(app);
      
          Runner *runner = new Runner(&app);
          QTimer::singleShot(0, runner, SLOT(run()));
          return app.exec();
      }
      
      

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      GuerrianG 1 Reply Last reply
      1
      • KroMignonK KroMignon

        @Guerrian QCommandLineParser should be place in main()!

        int main(int argc, char *argv[])
        {
            QCoreApplication app(argc, argv);
        
            QCommandLineParser parser;
            parser.setApplicationDescription("Description...");
            parser.addHelpOption();
        
            parser.process(app);
        
            Runner *runner = new Runner(&app);
            QTimer::singleShot(0, runner, SLOT(run()));
            return app.exec();
        }
        
        
        GuerrianG Offline
        GuerrianG Offline
        Guerrian
        wrote on last edited by
        #3

        @KroMignon Still doesn't work with Valgrind... no output.

        Linux Mint 18.3
        Qt 5.14.1
        Qt Creator 4.11.1

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Both testcases work fine for me on the command line, with or without valgrind.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          GuerrianG 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            Both testcases work fine for me on the command line, with or without valgrind.

            GuerrianG Offline
            GuerrianG Offline
            Guerrian
            wrote on last edited by
            #5

            @Christian-Ehrlicher I tried running on the command line and I got the message:

            error while loading shared libraries: libMyLib.so.0: cannot open shared object file: No such file or directory
            

            So then I created a bash script just called "myscript":

            #!bin/bash
            LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/daniel/Documents/MYLIB/lib
            export LD_LIBRARY_PATH
            exec "./MyApp"
            

            And made it executable:

            chmod +x myscript
            

            But when I run it says:

            bash: ./myscript: bin/bash: bad interpreter: No such file or directory
            

            Linux Mint 18.3
            Qt 5.14.1
            Qt Creator 4.11.1

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I'm pretty sure you don't have bin/bash in your current work dir...

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              GuerrianG 1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                I'm pretty sure you don't have bin/bash in your current work dir...

                GuerrianG Offline
                GuerrianG Offline
                Guerrian
                wrote on last edited by
                #7

                @Christian-Ehrlicher I forgot the slash, it should be:

                #!/bin/bash
                

                Linux Mint 18.3
                Qt 5.14.1
                Qt Creator 4.11.1

                1 Reply Last reply
                2
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Guerrian said in QCoreApplication console application does not output with Valgrind:

                  I forgot the slash

                  correct :)

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  1

                  • Login

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