[QUOTE=andreaQt;308744]In my project i have this 4 classes in separated .h and .cpp file:
built_sphere_window = new BuiltSphere;
built_cylinder_window = new BuiltCylinder;
glWidgetWindow = new GlWidget;
....}
glWidgetCylinder = new GlWidget;
....}
{
glWidgetSphere = new GlWidget;
....}
alpha = 0; //previous =>25
beta = 0; //previous =>-25
distance = 6; //previous =>2.5
initializeWindow();
....}
MainWindow::MainWindow(QWidget *parent): QWidget (parent){
built_sphere_window = new BuiltSphere;
built_cylinder_window = new BuiltCylinder;
glWidgetWindow = new GlWidget;
....}
BuiltCylinder::BuiltCylinder(QWidget *parent) : QWidget(parent){
glWidgetCylinder = new GlWidget;
....}
BuiltSphere::BuiltSphere(QWidget *parent) : QWidget(parent)
{
glWidgetSphere = new GlWidget;
....}
GlWidget::GlWidget(QWidget *parent) : QGLWidget(QGLFormat(/* Additional format options */), parent){
alpha = 0; //previous =>25
beta = 0; //previous =>-25
distance = 6; //previous =>2.5
initializeWindow();
....}
To copy to clipboard, switch view to plain text mode
from the "mainwindow" i do this calls:
void MainWindow::built_sphere(){
built_sphere_window->setWindowTitle("Built Sphere");
built_sphere_window->setWindowModality(Qt::ApplicationModal);
built_sphere_window->num_sphere = num_element_inserted->at(1)+1;
built_sphere_window->show();
}
void MainWindow::built_cylinder(){
built_cylinder_window->setWindowTitle("Built Cylinder");
built_cylinder_window->setWindowModality(Qt::ApplicationModal);
built_cylinder_window->num_cyl = num_element_inserted->at(0)+1;
built_cylinder_window->show();
}
void MainWindow::built_sphere(){
built_sphere_window->setWindowTitle("Built Sphere");
built_sphere_window->setWindowModality(Qt::ApplicationModal);
built_sphere_window->num_sphere = num_element_inserted->at(1)+1;
built_sphere_window->show();
}
void MainWindow::built_cylinder(){
built_cylinder_window->setWindowTitle("Built Cylinder");
built_cylinder_window->setWindowModality(Qt::ApplicationModal);
built_cylinder_window->num_cyl = num_element_inserted->at(0)+1;
built_cylinder_window->show();
}
To copy to clipboard, switch view to plain text mode
I have several object to build but at this time just the previous 2.
when i open one of this window i to read the data from the respective var & i'm right to visualize the number of the new object that i want to build.
My question is:
how i can set correctly the signal to send to mainwindow the number that i want only at push to ok button in the build window?
in mainwindow.cpp i think i have to set (i write the call for one build element):
connect (built_sphere_window, SIGNAL (sig_update_num(const int)), this, SLOT (update_value(const float)));
connect (built_sphere_window, SIGNAL (sig_update_num(const int)), this, SLOT (update_value(const float)));
To copy to clipboard, switch view to plain text mode
and in the respective slot update the num_element_inserted.
in builtsphere.h:
signals:
void sig_update_num(const int);
signals:
void sig_update_num(const int);
To copy to clipboard, switch view to plain text mode
in builtsphere.cpp:
emit sig_update_num(num_sphere+1)
emit sig_update_num(num_sphere+1)
To copy to clipboard, switch view to plain text mode
I think that the code write like this work, my finally question is:
if i want to read/write a value that is stored in a variable in the main window or in all of other classes from one of it is better do a "QSharedMemory+signal in a class like shareddata.h" to do the job or with the code that i write above?
At this time i do my application in one thread (i want to test it first that run correctly & do the job that i want), next step is do multithread to optimize the performance in multicore processor; so i think that in multithread is better to build a class shareddata.h where i can use the lock() & unlock() functions, is the right way to do the job?
After some test i have integrated this code & its work:
void MainWindow::built_sphere(){
built_sphere_window->setWindowTitle("Built Sphere");
built_sphere_window->setWindowModality(Qt::ApplicationModal);
built_sphere_window->num_sphere = num_element_inserted.at(0)+1;
built_sphere_window
->num_sphere_label
->setText
(tr
("Sphere %1").
arg(QString::number(built_Sphere_window
->num_cyl
)));
built_sphere_window->show();
}
void MainWindow::built_sphere(){
built_sphere_window->setWindowTitle("Built Sphere");
built_sphere_window->setWindowModality(Qt::ApplicationModal);
built_sphere_window->num_sphere = num_element_inserted.at(0)+1;
built_sphere_window->num_sphere_label->setText(tr("Sphere %1").arg(QString::number(built_Sphere_window->num_cyl)));
built_sphere_window->show();
}
To copy to clipboard, switch view to plain text mode
I still waiting for an answer about "QSharedMemory+signal in a class like shareddata.h"
Bookmarks