D
D
DDD2022-01-18 13:54:23
Qt
DDD, 2022-01-18 13:54:23

Why is the lineEdit field not responding to enter?

Hello!
I want to create a command line in qt using the QProcess class, but I have a problem, the lineEdit field does not react at all to pressing enter, please help me figure out what the problem might be.

#include "secondwindow.h"
#include "ui_secondwindow.h"
#include <QNetworkInterface>
#include <QDebug>
#include <QHostInfo>
#include <QObject>
#include <QTextCodec>
#include <QtNetwork>
#include <QProcess>

SecondWindow::SecondWindow(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SecondWindow)
{
    ui->setupUi(this);

    m_process = new QProcess(this);
        connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(setStdout()) );
        connect(ui->lineEdit_4, SIGNAL(returnPressed()), this, SLOT(command()) );
}

SecondWindow::~SecondWindow()
{
    delete ui;
}
void SecondWindow::setStdout()
{
    if(QSysInfo::productType()=="windows")
    {
        QTextCodec *codec = QTextCodec::codecForName("IBM 866");
        ui->textEdit->append( codec->toUnicode(m_process->readAllStandardOutput() ) );
    }
    else
        ui->textEdit->append( m_process->readAllStandardOutput() );
}
void SecondWindow::command()
{
    QString strCommand;
    if(QSysInfo::productType()=="windows")
        strCommand = "cmd /C ";
    strCommand += ui->lineEdit_4->text();
    m_process->start(strCommand);
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question