Solved error:Void Function Returning a Value ! Help!
-
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QByteArray> #include <QProcess> #include <Windows.h> #include <iostream> #include <string> #include <cstdlib> #include <stdlib.h> #include<QDebug> 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() { QProcess proc; proc.start("C:\\Program Files\\Git\\bin\\bash.exe", QStringList()); if (!proc.waitForStarted()) { return 1; } proc.write("git init "); QByteArray output; if (proc.waitForReadyRead()) { output += proc.readAll(); } qDebug() << output; }
i keep getting this error :c2562 'MainWindow::on_push_button_clicked":'void' function keep returning a value. when i try to compile the code. I m new to qt and c++ , anyone here can tell me what is the cause of the error. thanks you
-
As the error says, you are returning a value in a void function.
if (!proc.waitForStarted()) { return 1; }
Replace this by
if (!proc.waitForStarted()) { return; }
-