Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question