fork(1) download
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include <QInputDialog>
  6. #include <QLabel>
  7. QT_BEGIN_NAMESPACE
  8. namespace Ui { class MainWindow; }
  9. QT_END_NAMESPACE
  10.  
  11. class MainWindow : public QMainWindow
  12. {
  13. Q_OBJECT
  14.  
  15. public:
  16. MainWindow(QWidget *parent = nullptr);
  17. ~MainWindow();
  18. signals:
  19. void enter();
  20. private slots:
  21. void on_Generate_clicked();
  22. public slots:
  23. void gen();
  24. void lb();
  25. private:
  26. Ui::MainWindow *ui;
  27. int wid,hei;
  28. QVector<QVector<QPushButton*>> df;
  29. QLabel* lbl;
  30. };
  31. #endif // MAINWINDOW_H
  32.  
  33. //MAINWINDOW_CPP
  34. #include "mainwindow.h"
  35. #include "ui_mainwindow.h"
  36. #include <QLabel>
  37. #include <QDebug>
  38. MainWindow::MainWindow(QWidget *parent)
  39. : QMainWindow(parent)
  40. , ui(new Ui::MainWindow)
  41. {
  42. ui->setupUi(this);
  43. QPushButton* f = ui->Generate;
  44. ui->Generate->move((width()-f->width())/2,f->pos().y());
  45. }
  46.  
  47. MainWindow::~MainWindow()
  48. {
  49. delete ui;
  50. }
  51.  
  52.  
  53. void MainWindow::on_Generate_clicked()
  54. {
  55. wid = QInputDialog::getInt(this,"Widht","Widht",0,0,70);
  56. hei = QInputDialog::getInt(this,"Height","Height",0,0,70);
  57. emit enter();
  58. }
  59.  
  60. void MainWindow::gen(){
  61. for(int i=0; i < wid;i++){
  62. df.push_back(QVector<QPushButton*>());
  63. for(int j=0;j<hei;j++){
  64. df[i].push_back(new QPushButton(this));
  65. df[i][j]->setGeometry(20*i,20*j+30,20,20);
  66. df[i][j]->show();
  67.  
  68. QObject::connect(df[i][j], &QPushButton::clicked, this, &MainWindow::lb);
  69. }
  70.  
  71. }
  72.  
  73.  
  74.  
  75. }
  76.  
  77. void MainWindow::lb(){
  78. QObject *senderObj = sender();
  79. qDebug() << senderObj->objectName();
  80. }
  81.  
  82. //main
  83. #include "mainwindow.h"
  84.  
  85. #include <QApplication>
  86.  
  87. int main(int argc, char *argv[])
  88. {
  89. QApplication a(argc, argv);
  90. MainWindow w;
  91. w.show();
  92. QObject::connect(&w,&MainWindow::enter,&MainWindow::gen);
  93. return a.exec();
  94. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:10: fatal error: QMainWindow: No such file or directory
 #include <QMainWindow>
          ^~~~~~~~~~~~~
compilation terminated.
stdout
Standard output is empty