Внешние переменные не передают Qt ⇐ C++
-
Гость
Внешние переменные не передают Qt
Я пытаюсь создать программу, которая принимает входные данные из внешнего файла «C:/Repo/GraphTestData.txt».
Это происходит в моем файле main.cpp, где он анализируется на два двойных QVectors x и y. Затем я экспортирую x и y извне в общий заголовок «data.h», откуда доступ к ним осуществляется в другом файле с именем «networkplot.cpp». Здесь я использую QCustomPlot для отображения данных на графике. Однако консоль сообщает, что data.h не используется напрямую ни одним из файлов cpp. Как я могу это исправить?
// data.h #ifndef DATA_H #define DATA_H #include extern QVector x; extern QVector y; #endif // ДАННЫЕ_H #ifndef NETWORKPLOT_H #define NETWORKPLOT_H #include #include QT_BEGIN_NAMESPACE пространство имен Ui { class networkplot; } QT_END_NAMESPACE класс networkplot: public QMainWindow { Q_OBJECT публика: networkplot (QWidget *parent = nullptr); ~сетевой график(); частный: Ui::networkplot *ui; }; #endif // NETWORKPLOT_H #include "networkplot.h" #include "ui_networkplot.h" #include #include "data.h" networkplot::networkplot(QWidget *parent) : QMainWindow(родительский) , ui(новый Ui::networkplot) { ui->setupUi(это); extern QVector x, y; /*QVector x(100),y(100); for(int i=0;icustomplot->addGraph(); ui->customplot->graph(0)->setScatterStyle(QCPScatterStyle::ssDot); ui->customplot->graph()->setLineStyle(QCPGraph::lsLine); ui->customplot->xAxis->setLabel("X"); ui->customplot->yAxis->setLabel("Y"); ui->customplot->yAxis->setRange(-6000,100); ui->customplot->yAxis->setRange(-6000,8000); ui->customplot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); ui->customplot->graph(0)->setData(x,y); ui->customplot->rescaleAxes(); ui->customplot->replot(); ui->customplot->update(); } сетевой график::~networkplot() { удалить интерфейс; } #include "networkplot.h" #include #include #include #include #include #include "data.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); // Путь к файлу QString filePath = "C:/Repo/GraphTestData.txt"; // Векторы для хранения данных QVector x; QVector y; //Открываем файл QFile файл (путь к файлу); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug()
Я пытаюсь создать программу, которая принимает входные данные из внешнего файла «C:/Repo/GraphTestData.txt».
Это происходит в моем файле main.cpp, где он анализируется на два двойных QVectors x и y. Затем я экспортирую x и y извне в общий заголовок «data.h», откуда доступ к ним осуществляется в другом файле с именем «networkplot.cpp». Здесь я использую QCustomPlot для отображения данных на графике. Однако консоль сообщает, что data.h не используется напрямую ни одним из файлов cpp. Как я могу это исправить?
// data.h #ifndef DATA_H #define DATA_H #include extern QVector x; extern QVector y; #endif // ДАННЫЕ_H #ifndef NETWORKPLOT_H #define NETWORKPLOT_H #include #include QT_BEGIN_NAMESPACE пространство имен Ui { class networkplot; } QT_END_NAMESPACE класс networkplot: public QMainWindow { Q_OBJECT публика: networkplot (QWidget *parent = nullptr); ~сетевой график(); частный: Ui::networkplot *ui; }; #endif // NETWORKPLOT_H #include "networkplot.h" #include "ui_networkplot.h" #include #include "data.h" networkplot::networkplot(QWidget *parent) : QMainWindow(родительский) , ui(новый Ui::networkplot) { ui->setupUi(это); extern QVector x, y; /*QVector x(100),y(100); for(int i=0;icustomplot->addGraph(); ui->customplot->graph(0)->setScatterStyle(QCPScatterStyle::ssDot); ui->customplot->graph()->setLineStyle(QCPGraph::lsLine); ui->customplot->xAxis->setLabel("X"); ui->customplot->yAxis->setLabel("Y"); ui->customplot->yAxis->setRange(-6000,100); ui->customplot->yAxis->setRange(-6000,8000); ui->customplot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); ui->customplot->graph(0)->setData(x,y); ui->customplot->rescaleAxes(); ui->customplot->replot(); ui->customplot->update(); } сетевой график::~networkplot() { удалить интерфейс; } #include "networkplot.h" #include #include #include #include #include #include "data.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); // Путь к файлу QString filePath = "C:/Repo/GraphTestData.txt"; // Векторы для хранения данных QVector x; QVector y; //Открываем файл QFile файл (путь к файлу); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug()
Мобильная версия