Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 仅当窗口在QT中终止时,执行才会继续_C++_Qt - Fatal编程技术网

C++ 仅当窗口在QT中终止时,执行才会继续

C++ 仅当窗口在QT中终止时,执行才会继续,c++,qt,C++,Qt,我正在为GUI应用程序使用Qt Creator。我正在使用Ubuntu操作系统 我在GUI中有两个按钮,但除非按下另一个按钮,否则它不会工作 如果我按下一个按钮,它将不会显示任何输出,如果我关闭主窗口,输出将打印在控制台上 这是头文件 #ifndef MYMAINWINDOW_H #define MYMAINWINDOW_H #include <QPushButton> #include <QFileDialog> #include <QMessageBox>

我正在为GUI应用程序使用Qt Creator。我正在使用Ubuntu操作系统

我在GUI中有两个按钮,但除非按下另一个按钮,否则它不会工作

如果我按下一个按钮,它将不会显示任何输出,如果我关闭主窗口,输出将打印在控制台上

这是头文件

#ifndef MYMAINWINDOW_H
#define MYMAINWINDOW_H
#include <QPushButton>
#include <QFileDialog>
#include <QMessageBox>
#include <QMainWindow>
#include <QVBoxLayout>


class MyMainWindow: public QMainWindow
{
  Q_OBJECT

public:
  MyMainWindow(QWidget * parent = 0);
  virtual ~ MyMainWindow();



 private slots:
  void clickedRun();
  void filechooser();


private:

  QPushButton *button,*button2;
  std::string getFileExt(std::string s);

 };
#endif // MYMAINWINDOW_H

\ifndef mymain窗口
#定义MyMain窗口
#包括
#包括
#包括
#包括
#包括
类MyMainWindow:公共QMainWindow
{
Q_对象
公众:
MyMain窗口(QWidget*parent=0);
虚拟~MyMainWindow();
专用插槽:
void clickedRun();
void filechooser();
私人:
QPushButton*按钮,*按钮2;
std::string getFileExt(std::string s);
};
#endif//mymain窗口
这是cpp文件

#include <QPushButton>
#include <QFileDialog>
#include <QMessageBox>
#include <QMainWindow>
#include <QVBoxLayout>
#include <iostream>
#include <QDebug>
QStringList Listoffiles;
std::string headerfilename,sourcefile;
MyMainWindow::MyMainWindow(QWidget * parent) : QMainWindow (parent)
{

    setWindowTitle("welcome");
    QPushButton *button = new QPushButton(this);
    QPushButton *button2 = new QPushButton(this);

    button->setText("Choose Files");
    button2->setText("Run");

    QObject::connect(button, SIGNAL(clicked()),this, SLOT(filechooser()));
    QObject::connect(button2, SIGNAL(clicked()),this, SLOT(clickedRun()));

    button->move(100, 100);
    button->show();
    button2->move(300,100);
    button2->show();


    setWindowTitle("Pushbutton Clicked Signal Test");
    show();

}

MyMainWindow::~MyMainWindow()
{
}
  void MyMainWindow::clickedRun()
  {
       qDebug() << "inside run \n";

  }

  void MyMainWindow::filechooser()
  {
      QFileDialog dialog(this);
      dialog.setFileMode(QFileDialog::ExistingFiles);
      //dialog.setFileMode(QFileDialog::AnyFile);
      if(dialog.exec())
      {
          Listoffiles = dialog.selectedFiles();

      }
      std::cout << Listoffiles.count() <<" Files selected \n";
      int i = 0;
      for(QString q: Listoffiles)
      {
        qDebug()<<"how many times "<< ++i;

      std::string file = q.toUtf8().constData();
      if(getFileExt(file)=="h")
      {
          headerfilename = file;
           std::cout << "\nIncluded header file : ";
           std::cout << headerfilename;

      }else if(getFileExt(file)=="cpp")
      {
          sourcefile = file;
          std::cout << "\nFile selected to run : " << sourcefile << std::endl;
      }
    }
      dialog.close();
  }

  std::string MyMainWindow::getFileExt(std::string s){
  size_t i = s.rfind('.',s.length());
  if(i!= std::string::npos)
  {
  return (s.substr(i+1,s.length()-1));
  }
  return ("");
  }


#包括
#包括
#包括
#包括
#包括
#包括
#包括
qstringlistoffiles;
std::string headerfilename,sourcefile;
MyMainWindow::MyMainWindow(QWidget*parent):QMainWindow(parent)
{
setWindowTitle(“欢迎”);
QPushButton*按钮=新的QPushButton(此按钮);
QPushButton*button2=新的QPushButton(此按钮);
按钮->设置文本(“选择文件”);
按钮2->setText(“运行”);
QObject::connect(按钮、信号(单击())、此、插槽(filechooser());
QObject::connect(按钮2,信号(点击()),此,插槽(点击运行());
按钮->移动(100100);
按钮->显示();
按钮2->移动(300100);
按钮2->show();
setWindowTitle(“按钮点击信号测试”);
show();
}
MyMainWindow::~MyMainWindow()
{
}
void MyMain窗口::clickedRun()
{

qDebug()读取。(在命令行上)使用
g++-g-Wall
读取代码。另外,请仔细阅读。它可能是一个模态对话框。没有理由在构造函数中调用show(),实际上是调用window.show()后来…问题解决了。我只是更改了filechooser函数的执行。一切都很好。请阅读。(在命令行上)使用
g++-g-Wall
编写的代码。另外,请仔细阅读。这可能是一个模式对话框。没有理由在构造函数中调用show(),实际上是在调用window.show()后来…问题解决了。我只是更改了filechooser函数的执行。一切都很好。
#include <QApplication>
#include <QMainWindow>
#include "MyMainWindow.h"

int main(int argc, char *argv[])
{
  QApplication app(argc, argv);
  MyMainWindow window;

  //window.setWindowTitle(QString::fromUtf8("MainWindow"));
  window.resize(700,500);
  window.show();

  return app.exec();

}