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. pipe console output in a fortran func (inside a QThread) to Qt GUI ?
Forum Updated to NodeBB v4.3 + New Features

pipe console output in a fortran func (inside a QThread) to Qt GUI ?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 901 Views 2 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.
  • JoeCFDJ Offline
    JoeCFDJ Offline
    JoeCFD
    wrote on last edited by aha_1980
    #1

    How to pipe console output in a fortran func(inside a QThread) to Qt GUI ?
    I am using a QThread to run a fortran function and would like to get the console output from the fortran func for display on my Qt widgets. How to do it?
    I know how to run a fortran program with QProcess and get fortran output inside my Qt code with QProcess::readyReadStandardOutput(). However, QThread does not have similar functions. It seems I can not run a fortran func with QProcess. Thanks for your help in advance.

    kshegunovK 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you show how you run your fortran code with QThread ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by
        #3

        I made a class FPreprocessor which inherits QObject like worker class.
        auto preprocessor = new FPreprocessor;
        preprcoessor->moveToThread( my_thread );
        connect....
        connect( this, &prerun, preprocessor, &FPreprocessor::run)
        my_thread->start();
        emit prerun();
        FPreprocessor has a func run() which is called when signal prerun is emitted.
        fortran function call is made inside FPreprocessor::run();

        1 Reply Last reply
        0
        • JoeCFDJ JoeCFD

          How to pipe console output in a fortran func(inside a QThread) to Qt GUI ?
          I am using a QThread to run a fortran function and would like to get the console output from the fortran func for display on my Qt widgets. How to do it?
          I know how to run a fortran program with QProcess and get fortran output inside my Qt code with QProcess::readyReadStandardOutput(). However, QThread does not have similar functions. It seems I can not run a fortran func with QProcess. Thanks for your help in advance.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          A function is not a process, and a thread is not a process (mostly), so what you want is not possible. You can try to follow what's mentioned here, however, call me a cynic, but I really, really doubt the wisdom of it. You'd be better off actually using a C function you define be called in the fortran routine (or w/e it is) to bring you back whatever it is you need.

          Read and abide by the Qt Code of Conduct

          JoeCFDJ 1 Reply Last reply
          2
          • kshegunovK kshegunov

            A function is not a process, and a thread is not a process (mostly), so what you want is not possible. You can try to follow what's mentioned here, however, call me a cynic, but I really, really doubt the wisdom of it. You'd be better off actually using a C function you define be called in the fortran routine (or w/e it is) to bring you back whatever it is you need.

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #5

            @kshegunov Thanks for your reply. That is what I thought too. I am trying to make a c function to be called from fortran code. This c function can forward fortran output to my GUI. It is a bit messy. I will let you know if it works. However, I still doubt it is impossible for the GUI to catch the fortran output directly.

            kshegunovK 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @kshegunov Thanks for your reply. That is what I thought too. I am trying to make a c function to be called from fortran code. This c function can forward fortran output to my GUI. It is a bit messy. I will let you know if it works. However, I still doubt it is impossible for the GUI to catch the fortran output directly.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #6

              @JoeCFD said in pipe console output in a fortran func (inside a QThread) to Qt GUI ?:

              It is a bit messy. I will let you know if it works.

              Not more than calling a procedure in fortran instead of WRITE.

              However, I still doubt it is impossible for the GUI to catch the fortran output directly.

              This is not fortran output. The standard input and output are files that are prepared (and opened) for you by the runtime. Trying to hijack them can have unforeseen consequences on top of you being required to parse whatever it is written to them. How is this worse:

              extern "C" void my_callback_(double * theValueINeed)
              {
                  double valueFromFortran = *theValueINeed;       // Save this value to your C/C++ code's part or w/e
              }
              
              subroutine ReportToC(valueToReport)
              	real(kind = 8), intent(in) :: valueToReport
              	call my_callback(valueToReport)
              end subroutine ReportToC
              

              I'd say it's much better to have:

              call ReportToC(234.1)
              

              instead of trying to stitch up some frail workaround.

              Don't get this the wrong way, I know where you're coming from. I've seen quite a lot of fortran code and most of it looks like it was written by half-braindead monkeys, so you still are going to need to find where you have to inject these callbacks. It's a massive undertaking by itself.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              3
              • JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by
                #7

                Hooked it up with a c callback func and a worker class. Able to send fortran output to my GUI for display now. Many Thanks

                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