目录
- 准备
- 程序
- 界面
准备
1.ubuntu16建qt界面左上角菜单被遮挡
(ubuntu18不用)
进入:设置->外观->行为
显示窗口菜单—设置为“在窗口的标题栏”
菜单可见度—设置为“总是显示”
2.在pro文件末尾加入:QMAKE_LFLAGS += -no-pie
程序
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{Q_OBJECTpublic:explicit MainWindow(QWidget *parent = 0);~MainWindow();private slots:void on_pushButton_clicked();void on_pushButton_2_clicked();void on_pushButton_3_clicked();void on_pushButton_4_clicked();void on_pushButton_5_clicked();void on_pushButton_6_clicked();void on_pushButton_7_clicked();void on_pushButton_8_clicked();void on_pushButton_9_clicked();void on_action_triggered();void on_action_2_triggered();void on_action_3_triggered();private:Ui::MainWindow *ui;
};#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QProcess>
#include <QDir>
#include <QMessageBox>
#include <QDebug>MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{ui->setupUi(this);//this->setWindowTitle("control");ui->lineEdit->setText("nefu");ui->lineEdit_2->setText("/home/nefu");
}MainWindow::~MainWindow()
{delete ui;
}
//ros
void MainWindow::on_pushButton_clicked()
{system("gnome-terminal -- bash -c 'source /opt/ros/kinetic/setup.bash ;roscore'&");ui->textEdit->append("control $ : roscore");
}
//雷达
void MainWindow::on_pushButton_2_clicked()
{system("gnome-terminal -- bash -c 'source /home/nefu/catkin_ws/devel/setup.bash ;roslaunch velodyne_pointcloud VLP16_points.launch'&");ui->textEdit->append("control $ : roslaunch velodyne_pointcloud VLP16_points.launch");
}
//惯导
void MainWindow::on_pushButton_3_clicked()
{system("gnome-terminal -- bash -c 'source /home/nefu/catkin_ws/devel/setup.bash ;roslaunch sbg_driver sbg_device.launch'&");ui->textEdit->append("control $ : roslaunch sbg_driver sbg_device.launch");
}
//红外
void MainWindow::on_pushButton_4_clicked()
{system("gnome-terminal -- bash -c 'source /home/nefu/catkin_ws/devel/setup.bash ;roslaunch usb_cam usb_cam-test.launch'&");ui->textEdit->append("control $ : roslaunch usb_cam usb_cam-test.launch");
}
//大恒
void MainWindow::on_pushButton_5_clicked()
{system("gnome-terminal -- bash -c 'source /home/nefu/catkin_ws/devel/setup.bash ;rosrun daheng daheng_opencv'&");ui->textEdit->append("control $ : rosrun daheng daheng_opencv");
}
//rqt
void MainWindow::on_pushButton_6_clicked()
{system("gnome-terminal -- bash -c 'source /opt/ros/kinetic/setup.bash ;rqt_image_view '&");ui->textEdit->append("control $ : rqt_image_view");
}
//bag列表
void MainWindow::on_pushButton_7_clicked()
{ui->comboBox->clear();//QString strget=ui->lineEdit->text();QString Path=ui->lineEdit_2->text();//文件路径QDir dir(Path);//QDir dir(QDir::currentPath());//当前文件路径QString filtername = "*.bag";QStringList filter;filter << filtername;dir.setNameFilters(filter);QStringList Neuronindex = dir.entryList();ui->comboBox->addItems(Neuronindex);//把列表加载到comboBoxQString s = QString::number(Neuronindex.size());//bag文件个数ui->textEdit->append(QString("control $ : There are %1 bag files").arg(s));
}
//运行bag
void MainWindow::on_pushButton_8_clicked()
{QString pathget=ui->lineEdit_2->text();QString bagname=ui->comboBox->currentText();QString strv=QString("rosbag play %1/%2").arg(pathget).arg(bagname);QString str=QString("gnome-terminal -- bash -c 'source /opt/ros/kinetic/setup.bash ; %1'&").arg(strv);char *n;QByteArray m=str.toLatin1();n=m.data();system(n);ui->textEdit->append(QString("control $ : %1").arg(strv));
}
//删除bag
void MainWindow::on_pushButton_9_clicked()
{QString pathget=ui->lineEdit_2->text();QString bagname=ui->comboBox->currentText();QString path =QString("%1/%2").arg(pathget).arg(bagname);//指定文件路径QFile fileTemp(path);QMessageBox msg(this);//对话框设置父组件msg.setWindowTitle("Prompt");//对话框标题msg.setText("Confirm the delete action ?");//对话框提示文本msg.setIcon(QMessageBox::Question);//设置图标类型Informationmsg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);//对话框上包含的按钮if(msg.exec() == QMessageBox::Yes)//模态调用{fileTemp.remove();ui->textEdit->append(QString("control $ : Deleted %1").arg(bagname));}on_pushButton_7_clicked();
}
//关闭终端
void MainWindow::on_action_triggered()
{system("gnome-terminal -- bash -c 'killall -9 bash'&");
}
//关机
void MainWindow::on_action_2_triggered()
{system("gnome-terminal -- bash -c 'shutdown -h now '&");
}
//重启
void MainWindow::on_action_3_triggered()
{system("gnome-terminal -- bash -c 'shutdown -r now '&");
}
main.cpp
#include "mainwindow.h"
#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);MainWindow w;w.show();return a.exec();
}
界面
界面搭建
菜单