Hi, i'm new to Qt (started on: C- 5 years ago; C++ June last year; Qt - since this January) and i got some questions... i'm trying stuff for the past week but unsuccessful:
1. How can i make a struct visible in another class so i can create instances of it in diferent headers? (Like in mainwindow.h above) (This is a c++ question, i know..)
2. After i got it working, i saw in this forum that i got to add my struct to qt metatype so i can use signal/slot. I got to do it inside the header or the cpp file where i declared it?

I just made a clean project:
main.cpp (default code)
|-mainwindow.ui (just a start button on it)
|-mainwindow.h
|-mainwindow.cpp
|-myclass.h
|-myclass.cpp



mainwindow.h:
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include <QString>
  6. #include <QDebug>
  7. #include "myclass.h"
  8.  
  9. namespace Ui {
  10. class MainWindow;
  11. }
  12. struct myStruct{
  13. int id;
  14. QString name;
  15. float height;
  16. };
  17.  
  18. class MainWindow : public QMainWindow
  19. {
  20. Q_OBJECT
  21.  
  22. public:
  23. explicit MainWindow(QWidget *parent = 0);
  24. ~MainWindow();
  25.  
  26. void startProgram();
  27.  
  28. signals:
  29. void sendToClass(myStruct data[5]);
  30.  
  31. private slots:
  32. void on_pushButton_clicked();
  33.  
  34. private:
  35. void send();
  36. Ui::MainWindow *ui;
  37. myclass mcObj;
  38. myStruct data[5];
  39. };
  40.  
  41. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 


mainwindow.cpp:
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4. MainWindow::MainWindow(QWidget *parent) :
  5. QMainWindow(parent),
  6. ui(new Ui::MainWindow)
  7. {
  8. ui->setupUi(this);
  9. }
  10.  
  11. MainWindow::~MainWindow()
  12. {
  13. delete ui;
  14. }
  15.  
  16. void MainWindow::startProgram()
  17. {
  18. data[0].id = 1001;
  19. data[0].name = "Mark";
  20. data[0].height = 1.78f;
  21.  
  22. emit sendToClass(data);
  23. }
  24.  
  25. void MainWindow::on_pushButton_clicked()
  26. {
  27. connect(this, &MainWindow::sendToClass, &mcObj, &myclass::receiveFromMain);
  28. startProgram();
  29. }
To copy to clipboard, switch view to plain text mode 


myclass.h:
Qt Code:
  1. #ifndef MYCLASS_H
  2. #define MYCLASS_H
  3.  
  4. #include <QObject>
  5.  
  6. class myclass : public QObject
  7. {
  8. Q_OBJECT
  9. public:
  10. explicit myclass(QObject *parent = 0);
  11.  
  12. void startStuff();
  13.  
  14. public slots:
  15. void receiveFromMain();
  16. };
  17.  
  18. #endif // MYCLASS_H
To copy to clipboard, switch view to plain text mode 


myclass.cpp:
Qt Code:
  1. #include "myclass.h"
  2.  
  3. myclass::myclass(QObject *parent) : QObject(parent)
  4. {
  5.  
  6. }
  7.  
  8. void myclass::startStuff()
  9. {
  10.  
  11. }
  12.  
  13. void myclass::receiveFromMain()
  14. {
  15. //Want to receive the struct here!
  16. }
To copy to clipboard, switch view to plain text mode 


I left it in blank because i just don't know how to make it!

Basically, in my real project i want to be able to receive position parameters from a socket class running with QtConcurrent, and pass it to several classes.. i could just pass: int id, QString Name, float x, float y, float z.... but it is much more clean with a struct or class!

that struct can be anywhere (or even transform it to a class, better for me..).. i just want it to be seen in almost every project files.. although i don't want to create global variables.. I just tried several ways and i can't do it.




Thank you in advance!