我在MathGL库中遇到问题,并在应用程序中创建MathGL实例。每次我尝试运行它都会出现错误,说QApplication必须在QWidget(QMathGL类继承)之前构造。您可以在下面找到我的main代码和与MainWindow类相关的所有函数:
mainwindow.cpp
obj.style.borderBottom='1px';
的main.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "functions.h"
#include "surface.h"
#include "error.h"
#include <QString>
#include <QFileDialog>
#include <GL/glut.h>
#include <cmath>
#include <fstream>
#include <mgl2/qmathgl.h>
surface graph;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_draw_clicked()
{
string s;
bool correct = 1;
error *errorWindow = new error(this);
s = ui->eqEdit->text().toStdString();
period fPeriod = period(ui->upEdit->text().toDouble(),ui->lowEdit->text().toDouble());
functionSum fSum = functionSum(s,fPeriod,ui->accEdit->text().toDouble());
for (int i = 0; i < fSum.accuracy; i++)
{
for (int j = 0; j < fSum.accuracy; j++)
{
if(isnan(fSum.zValues[i][j]) || isinf(fSum.zValues[i][j]))
{
correct = 0;
}
}
}
if(!correct)
{
errorWindow->show();
}
graph = surface(fSum);
}
void MainWindow::on_save_clicked()
{
QString plik;
string splik;
plik = QFileDialog::getSaveFileName(this,"Zapisz plik",QString(),"Pliki tekstowe (*.txt)");
splik = plik.toStdString();
ofstream saver;
saver.open(splik.c_str());
if (saver.is_open())
{
for(int i = 0; i < graph.points.size(); i++)
{
saver << graph.points[i].x << " " << graph.points[i].y << " " << graph.points[i].z << endl;
}
saver.close();
}
}
void MainWindow::on_load_clicked()
{
QString plik;
string splik;
plik = QFileDialog::getOpenFileName(this,"Otwórz plik",QString(),"Pliki tekstowe (*.txt)");
splik = plik.toStdString();
ifstream loader;
loader.open(splik.c_str());
graph.points.clear();
if(loader.is_open())
{
while(!loader.eof())
{
point a(0,0,0);
loader >> a.x >> a.y >> a.z;
graph.points.push_back(a);
}
loader.close();
}
}
void MainWindow::on_plot_clicked()
{
int a = sqrt(graph.points.size());
mglData x(a,a);
mglData y(a,a);
mglData z(a,a);
long long int k = 0;
for (long long int i = 0;i<sqrt(graph.points.size());i++)
{
for (long long int j = 0;j<sqrt(graph.points.size());j++)
{
x.a[i+a*j] = graph.points[k].x;
y.a[i+a*j] = graph.points[k].y;
z.a[i+a*j] = graph.points[k].z;
k++;
}
}
mglGraph plot;
plot.Rotate(50,60);
plot.Light(true);
plot.Surf(x,y,z);
QMathGL plotter;
plotter.setGraph(&plot);
plotter.show();
}