Detect if QTest is running - qt

I have a class which has multiple unit-tests. I run them every time in a main function using QTest::qExec(new Test_MyClass) call. I'd like to see some qDebug() output when operating with MyClass, but not while running tests. Are there any Qt #defines to help me with that?

Related

Start a background process on Qt and load responsive shell environment

I am playing around with Qt to create a simple GUI for some more advanced analysis with the software called OpenFOAM. Right now, I want to start an application of the toolbox OpenFOAM usingQProcess::execute. It is working but for the application I need to load the environment in the shell.
Commonly, if I work in the terminal I first do have to source the environment file that loads all libraries and solvers one can use. However, in Qt, I am not aware how to achieve that.
Example. In the terminal I need to do the following:
source /path/to/environementFile
simpleFoam > logFile << application
I want to start the application simpleFoam in the background of my GUI after clicking on a button. Right now, I do have the following:
QProcess::execute(QString("/home/shorty/OpenFOAM/platforms/bin/simpleFoam"));
This works but the shared library that are needed by the application are not loaded (missing source of the environment file). Is there a way how to process more commands within one execution call?

QTCreator Memcheck performing analysis without letting me run the actual program?

I am attempting to use QTCreator's Memcheck tool to analyze the memory of a QT project, which is a dynamic library. It uses a QT Gui (QMainWindow) to allow the user to select a file, which is then processed, and then eventually returns to the mainwindow.
However, I cannot seem to use Memcheck properly.
When I select "Memcheck" and hit run, it instantly goes to "Analyzing memory" without ever letting the Gui pop up.
This is problematic. How can I get memcheck to work with this program?
I had two main issues:
1: Valgrind does not seem to play nice with QT Gui applications. It generates logs that are thousands of entries long for all the work QT is doing before it even gets to my application.
I had to make a separate, small non-GUI C++ program that would drive instead of the GUI application.
2: When trying to run from the command line, I needed to set an environment variable by using export. This needs to be the same as LD_LIBRARY_PATHS in QT Creator.
So I ran:
export LD_LIBRARY_PATH=X where X was the exact value I copied from LD_LIBRARY_PATHS in the variable from the QT Project.
Note: Running from the command line may have not be neccesary now that it isn't a GUI Application, memcheck might have passed just fine. Haven't tested since.

Ways to use MPI executable in Qt?

I have developed an application which comprises of a frontend Qt-GUI and a solver EXE. As these two are independent module, I could successfully launch EXE in Qt-GUI by using a QProcess like below:
QProcess *myProcess = new QProcess;
myProcess->start(exeFilePath, args);
Where
exeFilePath = "EXE"
args = "input1 -option1 name1 -option2 name2"
From QProcess's signals, I could successfully read from output channels and update the progress in a Qt-GUI's QGLWidget.
Things have changed by time. EXE is now MPI-EXE, an MPI based executable and I need to use it through Qt-GUI in a practical way.
I tried the above QProcess exercise for MPI-EXE with the following change:
exeFilePath = "mpirun -np 4 MPI-EXE"
When doing this, myProcess could not be started and when error was printed, it gave UnknownError. As I understand, QProcess itself runs in a separate thread and from this I have to launch a 4-process MPI-EXE which makes this problematic.
I need help in :
How can I launch MPI-EXE without Qt-GUI freezing ?
How can I monitor progress of MPI-EXE as I have to plot the progress in QGLWidget ?
I will really appreciate any comments on my questions.
Please help. Thanks.

How to call an app that expects stdin input from QtGui?

I'm using Ubuntu and Qt Creator 4
I have a .cpp program in the executable form (say abc.out) that I wish to run when I press a button. It contains a number of cin and cout, so I want it to run on a "terminal" (on Ubuntu) so that I am able to input and output values to it. How can I do that?
I've tried system() and
also,
QProcess p1;
p1.start(./abc.out);
Using QProcess, my executable runs but stops at the first cout. It runs on the application output screen in Qt Creator and not on terminal.
For example:
I see on application output:
enter name:
When I type the value and press enter here, it doesn't accept the value, but moves to the next line and allows me to type further.
I want to run this abc.out file on the terminal. Any ideas would be really helpful.
Do you mean Qt Creator 2.4? In any case, on the Projects tab, you should find the Run settings section and from there you can find a "Run in terminal" checkbox. You could also use a Custom Executable option and type there: gnome-terminal --command ./abc.out The exact details can vary a bit as I'm using Qt Creator 2.5.
This should work when launching from Qt Creator, but when you use your app outside the IDE, you need to launch it from terminal and not by double clicking the executable. To fix this, I can think of two ways:
Launch a terminal window from QtGui (something like QProcess::execute("gnome-terminal --command ./abc.out"); ), though the problem is different systems have different terminal names.
Provide a Qt input/text box yourself as part of your GUI which then forwards the user input to the executable (something like myqprocess.write(input_asked_from_user_by_QtGui); ). Here you probably need to know what information to ask the user beforehand. If you want to display the cout output of the started process, you can use the read method and friends of the QProcess.
From your question I assume that you are writing an application that launches other applications using QProcess. Thats fine, but if your subprocess is waiting for data from the standard input it will wait forever since you did not provide any data. The stdin of your parent application cannot be automatically guided to the subprocess. Imagine you are starting two processes from your main app. To which child process should the input go?
If you want to communicate with child processes, you must use the QIODevice methods of QProcess and send/read data from/to that application.
The only sensible solution is to launch the target application in a terminal. Whether your own code provides the terminal window or you reuse an existing terminal application is up to you.

Problems with Multiple QApplications

Can someone help me understand what are the problems in running multiple QApplications on Qt for Embedded Linux? Please point me to some documentation of mailing-list threads.
While going through some of the mails in mailing lists, I have seen some comments which say that, running multiple QApplications in Qt is not supported by design and why at all it is required? How can I understand this more clearly?
However, while reading the document "Qt for Embedded Linux Architecture" I did not find anything which says that we should not run multiple QApplication instances at the same time.
I am executing two QApplications on a Embedded Linux platform (not a PC) and one of them in full screen mode. The one which is in fullScreen mode it is not getting keyboard focus, even though it receives mousePress events. If same app is run in normalMode, it gets the mousePress event followed by focusInEvent`.
Can somebody provide pointers on it?
You can run multiple processes each with one QApplication just fine.
However, with Qt for Embedded Linux, only one of these must be the QWS server. In other words, you should start the first process with `-qws', and all other processes without.
QApplication is a singleton class, so its "single" by design. You can have only a single QApplication object per program.
But in Qt there is no inherent limitation of the number of qt programs using the QApplication class you can run parallel. You can have more than one program using qt (and thus very likely QApplication) at the same time.
Probably this got somehow confused in your mailing lists.
My guess is that one QApplication would accept the mouse event or keyboard event and therefore the other would not get it.
Its probably a little random as to which QApplication accepts which events based on having so many QApplications in a single process.
I cannot imagine the use case as to why you would want multiple QApplications within a process. Could you expand on what you are trying to do?

Resources