D
D
DDD2021-01-02 21:54:38
Qt
DDD, 2021-01-02 21:54:38

C++QT Why does the window crash in the lineEdit field after pressing Enter?

I create my own command line console, but as soon as I enter some query into the lineEdit field and press Enter, the window crashes, what could be the problem?

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

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::on_pushButton_12_clicked()
{
    this->close();
    emit firstWindow();
}

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 ";
    strCommand += ui->lineEdit_4->text();
    m_process->start(strCommand);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jacob E, 2022-01-03
@Zifix

Did you find the line under the debugger where the crash occurs? Are there any errors that show up?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question