Hi all, so I built a simple HelloWorld static library and I want to use it in a GUI application (I named it GUI_stuff - poor name choosing I know..).
My static library has one function (this whole task is for training purposes) that prints a greeting to the console and returns nothing.
I found one way to use QProcess and the GUI_stuff executable to capture the HelloWorld static library output and redirect it to a QLabel.
However, I've been instructed to "fix" this -- i.e. don't rerun GUI_stuff in a child process and just capture the output from the static library.
I've searched high and low in the Qt forums and stackoverflow and have just tried about every solution - don't really know how to go about this.
I'm rather new to Qt as well.

Here is my .pro file:
Qt Code:
  1. QT += core gui
  2.  
  3. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  4.  
  5. QT += webenginewidgets
  6.  
  7. TARGET = GUI_stuff
  8. TEMPLATE = app
  9.  
  10. # The following define makes your compiler emit warnings if you use
  11. # any feature of Qt which has been marked as deprecated (the exact warnings
  12. # depend on your compiler). Please consult the documentation of the
  13. # deprecated API in order to know how to port your code away from it.
  14. DEFINES += QT_DEPRECATED_WARNINGS
  15.  
  16.  
  17. SOURCES += \
  18. main.cpp \
  19. mainwindow.cpp
  20.  
  21. HEADERS += \
  22. mainwindow.h
  23.  
  24. FORMS += \
  25. mainwindow.ui
  26.  
  27. win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/release/ -lHelloWorld
  28. else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/debug/ -lHelloWorld
  29. else:unix: LIBS += -L$$PWD/lib/ -lHelloWorld
  30.  
  31. INCLUDEPATH += $$PWD/.
  32. DEPENDPATH += $$PWD/.
  33.  
  34. win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/lib/release/libHelloWorld.a
  35. else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/lib/debug/libHelloWorld.a
  36. else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/lib/release/HelloWorld.lib
  37. else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/lib/debug/HelloWorld.lib
  38. else:unix: PRE_TARGETDEPS += $$PWD/lib/libHelloWorld.a
To copy to clipboard, switch view to plain text mode 


Here is my main.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include <QApplication>
  3. #include <QLabel>
  4. #include <QTextStream>
  5. #include <QFile>
  6. #include <QTextEdit>
  7. #include <QWebEngineView>
  8. #include "lib/helloworld.h"
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12. QApplication a(argc, argv);
  13.  
  14. HelloWorld hello_world;
  15. hello_world.display();
  16.  
  17. MainWindow w;
  18. w.show();
  19.  
  20. return a.exec();
  21. }
To copy to clipboard, switch view to plain text mode 

Here is my mainwindow.cpp file - note I'm only including the functions where I capture and redirect the stdout as this file is rather large
Qt Code:
  1. /**
  2.  * @brief MainWindow::on_pushButton_clicked
  3.  * This function is called when the "Greeting" button is clicked.
  4.  * This function starts a child process in which the console output printed in main()
  5.  * of main.cpp is obtained and stored into a variable to display on the GUI.
  6.  */
  7. void MainWindow::on_pushButton_clicked() {
  8. process = new QProcess;
  9. process->start("./GUI_stuff");
  10. process->waitForStarted(1000);
  11. connect(process,SIGNAL(readyRead()), this, SLOT(printLibData()));
  12. }
  13.  
  14. /**
  15.  * @brief MainWindow::printLibData
  16.  * This function is called when the process in function on_pushButton_clicked()
  17.  * reaches the readyRead() step. The process output is stored in a QString variable
  18.  * which is then displayed in the GUI via a QLabel
  19.  */
  20. void MainWindow::printLibData(){
  21. QString proc_buf = process->readLine();
  22. QLabel *greet_label = new QLabel(proc_buf, ui->centralWidget);
  23. greet_label->setIndent(450);
  24. greet_label->show();
  25. process->close();
  26. }
To copy to clipboard, switch view to plain text mode 

I need a way of capturing the output from hello_world.display() in main and redirect it to a QLabel -- please help as I've been stuck on this problem for a few days now...
By the way, the application itself is called GUI_stuff -- so I'm essentially running another GUI_stuff application to get the console output when running GUI_stuff application itself.
Is there a way to use signals and slots here? Is that the solution? Cuz I tried that as well with not much of a solution.