0

I have a issue, where I need the GUI from QT Designer to give values to a separate program running from terminal where the values from the GUI are "printed" onto the terminal interface (Linux with GCC compiler)

I have researched pthreads, but their application examples are limited to In-Application uses. The code in my main file is as follows:

#include "main_window.h"

#include <QApplication>

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>


void *thr_func(void *thread_id)
{
    int tid = thread_id;
    pthread_mutex_lock(&lock_x);
    cout << "thread" << tid << end1;
    cout << xValue << end1;
    cout << yValue << end1;
    cout << zValue << end1;
    pthread_mutex_unlock(&lock_x);
}

int main(int argc, char *argv[])
{
    pthread_create(thread_1, NULL, thr_func, NULL)

    while(true)
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
        return a.exec();
    }
    pthread_exit(NULL);
}

**Note that xValue, yValue, and zValue already stream to a textfile from the QT application. I am adapting the application for terminal running and control.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • If you're looking for running a "separate program", look at QProcess. Threads are for running separate functions in parallel within the same program. – JarMan Feb 11 '21 at 13:31
  • @JarMan The other program is just a SoC simulated in C++. Basically I just need this program to give values to it. The QT program is just a "controller". Do you have any pointers on how to in Linux? – silvias15Driver Feb 11 '21 at 14:07
  • Are you wanting to start a separate program with parameters that you provide? Or are you wanting to actually communicate with an already running program? – JarMan Feb 11 '21 at 14:10
  • @JarMan The simulation is already running. The GUI just provides input for a sensor – silvias15Driver Feb 11 '21 at 15:16
  • Ok, your question (and your code) is not clear to me then. Why are you asking about pthreads? If you want your gui app to talk to a separate console app, then you need to be looking up interprocess communication. – JarMan Feb 11 '21 at 15:21
  • 1
    Here's the relevant Qt [docs](https://doc.qt.io/qt-5/ipc.html) on IPC. – JarMan Feb 11 '21 at 15:22
  • @JarMan I will look into it. Thank you! – silvias15Driver Feb 11 '21 at 15:33

0 Answers0