64,683
社区成员
发帖
与我相关
我的任务
分享
#include "test.h"
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include"engine.h"
#include<windows.h>
#include <QComboBox>
#include <QLayout>
#include <iostream>
#include<string>//定义字符串
#include <QApplication>
#include <QWidget>
#pragma comment(lib,"libeng.lib")
#pragma comment(lib,"libmx.lib")
#pragma comment(lib,"libmat.lib")
Test::Test(QWidget *parent) //调整图片
: QMainWindow(parent)
{
ui.setupUi(this);
QImage Image;
Image.load("E:/QT/WORK/Test/Test/1400_01.gif");
QPixmap pixmap = QPixmap::fromImage(Image);
int with = ui.label_6->width();
int height = ui.label_6->height();
QPixmap fitpixmap = pixmap.scaled(with, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); // 饱满填充
//QPixmap fitpixmap = pixmap.scaled(with, height, Qt::KeepAspectRatio, Qt::SmoothTransformation); // 按比例缩放
ui.label_6->setPixmap(fitpixmap);
}
//% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%
void Test::on_conduct_2_clicked() //conduct
{
//获取输入参数
QString w = ui.label->text();
QString q = ui.label->text();
int qxs = q.toInt();
//检查是否有输入 messagebox函数 出报错对话框
QString aa = ui.label_7->text();
if (aa == "djbzz")
{
if (w.isEmpty())
{
MessageBoxA(NULL, "Error in intput", "Error", MB_OK); //通常我们手动输入的字符串都是const char*(即LPCSTR)类型的,因此只需将该句中的MessageBox改为MessageBoxA即可。
// MessageBox(NuLL,"str","str",MB_OK)
//MB_OK是按钮类型
return;
}
else
{
//检查引擎
Engine *ep; // open engine
if (!(ep = engOpen("\0")))
{
fprintf(stderr, "\nCan't start MATLAB engine\n");
/*return;*/
}
//方向图函数
int L = qxs;
const double PI = 3.1415926;
double *t = new double[L];
double *p = new double[L];
for (int i = 0; i < L; i++)
{
t[i] = 2 * PI*i / L;
}
for (int i = 0; i < L; i++)
{
p[i] = 1;
}
mxArray *T = NULL, *result = NULL;
T = mxCreateDoubleMatrix(1, 1, mxREAL); //应该是对mxArray *A这个指针所指的矩阵进行内存的申请,m是待申请矩阵的行数,n是待申请矩阵的列数
mxArray *P = NULL, *result1 = NULL;
P = mxCreateDoubleMatrix(1, 1, mxREAL);
memcpy((void*)mxGetPr(T), (void*)t, L * sizeof(t[0]));
memcpy((void*)mxGetPr(P), (void*)p, L * sizeof(t[0]));
engPutVariable(ep, "theta", T);//引号中的为matlab中的变量
/* engPutVariable(ep, "r", P);*/
engEvalString(ep, "djbzz");//调用m文件
//engEvalString(ep, "f=sin(theta);");
//engEvalString(ep, "f=abs(f);");
//engEvalString(ep, "subplot(1,2,1);");
//engEvalString(ep, "polar(theta,f);");
//engEvalString(ep, "title('E面方向图');");
//engEvalString(ep, "subplot(1,2,2);");
//engEvalString(ep, "polar(theta,r,'m');"); //需要交联c与matlab中R的变量 即按上述L过程从新定义
//engEvalString(ep, "title('H面方向图');");
//engEvalString(ep, "f=sin(theta);f=abs(f);");
//engEvalString(ep, "for k=1:L r(k) =1;end");
//engEvalString(ep, "subplot(1,2,1);polar(theta,f);title('E面方向图');title('E面方向图');subplot(1,2,2);polar(theta,r,'m');title('H面方向图');");//可以一条语句
for (int i = 0; i <=1000; i++) //加载框进度加载
{
ui.progressBar->setValue(i);
}
ui.label->clear();
}
}
if (aa=="jymz")
{
}
}
void Test::on_clean_clicked()
{
ui.checkBox->setChecked(false);
ui.checkBox_2->setChecked(false);
ui.checkBox_3->setChecked(false);
ui.label->clear();
ui.label_2->clear();
ui.label_3->clear();
ui.label_4->clear();
ui.label_5->clear();
}
void Test::on_checkBox_clicked()
{
}
void Test::on_checkBox_2_clicked()
{
}
void Test::on_checkBox_3_clicked()
{
}
//void Test::on_push_clicked()
//{
// QString aa = ui.label_7->text();
// if (aa=="djbzz")
// {
// ui.label_4->setText(aa);
// }
// /*ui.label_4->setText(aa);*/
//}
void Test::on_pushButton_clicked()//置入天线方向函数
{
ui.comboBox->clear();
ui.comboBox->addItem("djbzz", 1);
ui.comboBox->addItem("jymz",2);
ui.comboBox->addItem("shiyan", 3);
}
void Test::on_comboBox_currentIndexChanged(const QString &arg1)
{
ui.label_7->setText(arg1);
double aa = arg1.toDouble();
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_test.h"
#include <QProgressBar>
class Test : public QMainWindow
{
Q_OBJECT
public:
Test(QWidget *parent = Q_NULLPTR);
int x, y;
private:
Ui::TestClass ui;
QProgressBar *progressBar; //进度条 不用定义到 private solts
private slots:
void on_clean_clicked();
void on_conduct_2_clicked();
void on_checkBox_clicked();
void on_checkBox_2_clicked();
void on_checkBox_3_clicked();
/*void on_push_clicked();*/
/*void on_comboBox_clicked();*/
//void on_checkBox_stateChanged(int arg1);
//void on_checkBox_2_stateChanged(int arg1);
//void on_checkBox_3_stateChanged(int arg1); //用于开关互斥
//不写函数 不能定义
void on_pushButton_clicked();
void on_comboBox_currentIndexChanged(const QString &arg1);
};
mxArray *T = NULL, *result = NULL;
T = mxCreateDoubleMatrix(1, 1, mxREAL);
mxArray *P = NULL, *result1 = NULL;
P = mxCreateDoubleMatrix(1, 1, mxREAL);
这两句上,括号里应为(1,L,mxREAL) 第二项为1 后将会导致堆栈损坏。