Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6934593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:58:50+00:00 2026-05-27T11:58:50+00:00

I am trying to communicate an Erlang program with a simple Qt window app

  • 0

I am trying to communicate an Erlang program with a simple Qt window app through an Erlang port.

The problem is that the result from the Qt window event (on_pushButton_clicked()) shows up in Erlang port only after the window is closed and not when the button is pressed:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "stdio.h"
#include "choosefileform.h"

#include <iostream>
using namespace std;


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{

    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{

    fprintf(stdout, "window_input:");
    printf(ui->lineEdit->text().toAscii());
printf("~n");


    ChooseFileForm* fn  = new ChooseFileForm();

    this->close();
    fn->show();
}

Erlang (sending a Message just does nothing here, we are interested in getting data from Qt):

connect(Message) ->
    Cmd = "./myqtwindowapp \n",
    Port = open_port({spawn,Cmd}, [stream,use_stdio,exit_status]),
    Payload = string:concat(Message, "\n"),
    erlang:port_command(Port, Payload),
    receive
        {Port, {data, Data}} ->
            ?DBG("Received data: ~p~n", [Data]),
        Other ->
            io:format("Unexpected data: ~p~n", [Other])
    after 15000 ->
            ?DBG("Received nothing~n", [])
    end.

The result of running this and filling the text field in the window is nothing (Erlang gets nothing and just waits in the receive clause):

Only when I manually close the window Erlang says:

Received data: "window_input:hello"

So, why don’t I get data from Qt into Erlang port immediately?

UPD. Solution:

The solution was to flush() the Qt’s buffer:

instead of fprintf(stdout, "window_input:"); I used

cin >> c;
cout << c;
cout.flush();

And it worked.

P.S. However, I do not understand why this problem did not happen with testing the same Qt app in console – it returned data immediately I filled in the text field in the window (i.e. on event).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:58:51+00:00Added an answer on May 27, 2026 at 11:58 am

    I’m not so much experienced with C++ but seems you don’t flush data from your port. (And also "~n" is not new line in C++ which is not case because you use stream mode instead line.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to communicate with a cash register through the serial port from
I'm trying to pass some files from one app to another. I communicate the
I'm trying to communicate to a device using RS-485 through the serial port. Everything
I'm getting a 503 response from a server that I'm trying to communicate with.
I've been trying to communicate with Arduino through its serial port and with the
I get this message when trying to communicate with software that communicates with SOAP?
I have an applet that throws this exception when trying to communicate with the
I'm trying to communicate with a soap service and I know that I should
I am trying to communicate between two processes. From MSDN Documentation, I came across
I am trying to communicate with TCP between a Qt program and a regular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.