PDA

View Full Version : Problem in using UI object in other class



beginQT
17th January 2012, 16:02
Hello,

I am trying to use generated UI class object in my own helper class to control the functionality of the UI data(buttons) depending on the data.Here is the code:

Main.cpp


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//QT Created Class
PSX_HMI w;
w.show();

//Helper class which uses UI object
CPsxHMI_stateMechine stateMachine(w.getUI_Object(), w.getCANIO_DataObject());
return a.exec();
}


//CPsxHMI_stateMechine.cpp
CPsxHMI_stateMechine::CPsxHMI_stateMechine(Ui::PSX _HMIClass *f_UI_Data, cPsxHMI_CANIODataBase *f_CAN_Data)
:objPsx_HMI_ui(f_UI_Data),objCanIO_Data(f_CAN_Data )
{
//objPsx_HMI_ui = f_UI_Data;
//objCanIO_Data = f_CAN_Data;
objPSX_SM_Th = this;

this->start(QThread::HighPriority);
}

void CPsxHMI_stateMechine::run()
{
while(this->isRunning())
{
std::cout<<"State Mechine Thread Started"<<std::endl;
/* if((SystemActivation_Sys_PSC & objCanIO_Data->g_currentActiveFunc_sint32) || (SystemActivation_Sys_PP_PSC_cPSC & objCanIO_Data->g_currentActiveFunc_sint32))
objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/PSC_active.png)");
else
objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/PSC_notactive.png)");

if(SystemActivation_Sys_POC & objCanIO_Data->g_currentActiveFunc_sint32)
objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/POC_a.png)");
else
objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/POC_na.png)");

if(SystemActivation_Sys_SDW & objCanIO_Data->g_currentActiveFunc_sint32)
objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/SDW_a.png)");
else
objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/SDW_na.png)");

if(SystemActivation_Sys_SVA & objCanIO_Data->g_currentActiveFunc_sint32)
objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/SVA_a.png)");
else
objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/SVA_na.png)");*/
QThread::msleep(10);
}

}

When I am using objPsx_HMI_ui object which is UI class object I could not run my application, Some problem with runtime libraries. It opens and immediately resets.

Could any one help me in this regard?

Thanks in Advance!

beginQT
18th January 2012, 15:32
Hello,

Sorry for the confusion!

What I am looking for is something like user defined signals and slots.
I have few Qpushbuttons I need to show different stylesheets and to make them visible depending on some Data. I want to define some signals which takes this data and when the data changes i need to call some slot to do some operations.

Please help me in this regard.

Thanks in Advance!

ChrisW67
18th January 2012, 22:25
Signals and slots

beginQT
19th January 2012, 11:42
Hello,

Thanks for the reply.

I have gone through the link, I could not get solution for the problem I am looking for.

I have a QPushButton for which there are different button images to be shown for a particular button depending on some data change.

I mean I have different button images for same feature like ON, OFF and error. To take a decision on whether to show ON or OFF button image I am depending on some data coming from the lower layers. so, what I am trying to do is when this data changes I want to emit an signal with its value so that I can take decision on which button image to be displayed in slot.

I am trying to do the following but it is not working.



//in .h file
public slots:
void generate(int);

signals:
void PSCvalueChanged(int);




//Connect in Constructor of child class of QMainWindow
connect(ui.pushButton,SIGNAL(PSCvalueChanged(int)) ,this,SLOT(generate(int)));




//Helper function called by other class when data changes
void MultiGlWindows::emitSignals(int newValue)
{
emit PSCvalueChanged(newValue);
}

//Slot Defnition
void MultiGlWindows::generate(int value)
{


if(value == 3)
{
emit PSCvalueChanged(value);
ui.pushButton->setGeometry(5, 150, 140, 50);
ui.pushButton->setStyleSheet("image: url(:/debug/Images/APS_notactive.png)\n");
}
else{
ui.pushButton->setGeometry(5, 250, 140, 50);
ui.pushButton->setStyleSheet("image: url(:/debug/Images/APS_active.png)\n");
}
}


Could you please tell me where it went wrong? or do I need to follow any alternate approach?

Thanks in Advance!

wysota
19th January 2012, 11:53
I think your program has already told you (in the console) QPushButton didn't have a PSCvalueChanged(int) signal. Your app is smart, you should listen to it.

And start using layouts in your apps, please.