PDA

View Full Version : changing data type parameter in qt signals



ehntun
20th November 2012, 08:04
Hi Guys!

I have here question about Qt Signals:

How can i change the datatype of a parameter like this:

valueChanged(int) to valueChanged(unsigned long)?

Is it possible?

or how can i pass int to unsigned long in connect like this:

connect(ui->combobox,SIGNAL(valueChanged(int)),this, SLOT(mySLOT(unsigned long)));???

the code above is not working because i think(obviously they are not the same data type). it can't pass the int to the unsigned long. Can you guys help me regarding this. I need not to use int for my whole application.

Thanks in advance guys.

anda_skoa
20th November 2012, 10:20
You just add a second slot that has int as its argument's type and then call the one with unsigned int from there.

Cheers,
_

ehntun
20th November 2012, 10:26
Hi anda_skoa!

Thanks for your reply but I won't use int and unsigned int.

amleto
20th November 2012, 11:05
jees, you get the point, don't you?


myclass::my_conversion_slot(int x)
{
unsigned long ul = static_cast<unsigned long>(x);

emit some_other_signal(ul);
}

ehntun
20th November 2012, 11:17
Yes I get your point. But is there any way of not using int for the entire code? We are required not to use int Sir.

amleto
20th November 2012, 11:55
If you mean you are not allowed to use 'int' ANYWHERE and you want to use Qt, then you will not have an easy life. You will need to modify all Qt source code and rebuild (or insert a typedef everywhere and rebuild...).

Added after 11 minutes:

your code:
connect(ui->combobox,SIGNAL(valueChanged(int)),this, SLOT(mySLOT(unsigned long)));???
You still used int there! So now you are asking for something different than in your first post!

anda_skoa
20th November 2012, 17:40
If you mean you are not allowed to use 'int' ANYWHERE and you want to use Qt

Indeed, especially when the range of the int includes negative numbers, e.g. return value of QList::indexOf(), etc.

Cheers,
_

ehntun
21st November 2012, 00:28
Indeed, especially when the range of the int includes negative numbers, e.g. return value of QList::indexOf(), etc.

Cheers,
_

Yes Sir. You're right. Thanks for your replies. I'm just looking for a possible way for this situation but now i know this will make my life messier. lol.


If you mean you are not allowed to use 'int' ANYWHERE and you want to use Qt, then you will not have an easy life. You will need to modify all Qt source code and rebuild (or insert a typedef everywhere and rebuild...).

Added after 11 minutes:

your code:
connect(ui->combobox,SIGNAL(valueChanged(int)),this, SLOT(mySLOT(unsigned long)));???
You still used int there! So now you are asking for something different than in your first post!

Hi Sir amleto. Thanks for this info. Now i know this would consume a lot of time and will make my coding uneasy. I'm just looking for a way for implementing codes without using "int" as i was instructed. Thanks a lot Sir.

amleto
21st November 2012, 10:00
sounds like a crazy homework/coursework assignment. Not sure if it's worse than banning use of STL or not...