#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>namespace Ui {class MainWindow;}class MainWindow : public QMainWindow{ Q_OBJECTpublic: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow();private: Ui::MainWindow *ui;};#endif // MAINWINDOW_H
#include "mainwindow.h"#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this);}MainWindow::~MainWindow(){ delete ui;}
#include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; while (1) { w.show(); a.exec(); } return 0;}
XML<?xml version="1.0" encoding="UTF-8"?><ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>287</width> <height>265</height> </rect> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <widget class="QWidget" name="centralWidget"> <layout class="QGridLayout" name="gridLayout"> <item row="0" column="0"> <widget class="QLineEdit" name="lineEdit"/> </item> <item row="1" column="0"> <widget class="QSpinBox" name="spinBox"/> </item> </layout> </widget> </widget> <layoutdefault spacing="6" margin="11"/> <resources/> <connections/></ui>
//respawn.cpp#include <QApplication>#include <QWidget>#include <QString>int main(int argc, char** argv) { QApplication app(argc,argv); QWidget w; int ax=100,ay=100,aw=400,ah=300; if (argc == 5) { ax = QString::fromLocal8Bit(argv[1]).toInt(); ay = QString::fromLocal8Bit(argv[2]).toInt(); aw = QString::fromLocal8Bit(argv[3]).toInt(); ah = QString::fromLocal8Bit(argv[4]).toInt(); } w.setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint); w.setGeometry(ax,ay,aw,ah); while (1) { w.show(); app.exec(); }}
Bash#!/bin/sh ./respawn &./respawn 100 450 500 400 &
Bash#!/bin/sh pkill respawn
#include <QApplication>#include <QWidget>#include <QString>//#include <QDebug>#include <QMessageBox>int main(int argc, char** argv) { QApplication app(argc,argv); QWidget w; int ax=100,ay=100,aw=400,ah=300; if (argc == 5) { ax = QString::fromLocal8Bit(argv[1]).toInt(); ay = QString::fromLocal8Bit(argv[2]).toInt(); aw = QString::fromLocal8Bit(argv[3]).toInt(); ah = QString::fromLocal8Bit(argv[4]).toInt(); } //w.setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint); w.setGeometry(ax,ay,aw,ah); while (1) { w.show(); app.exec(); QMessageBox box; box.setIcon(QMessageBox::Warning); box.setText("<font color=red>Приложение остановлено<br>Перезапустить?</font>"); box.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); box.setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); int ok = box.exec(); if (ok != QMessageBox::Ok) break; }}
Bashpkill respawn