Results 1 to 9 of 9

Thread: changing data type parameter in qt signals

  1. #1
    Join Date
    Oct 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows

    Default changing data type parameter in qt signals

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: changing data type parameter in qt signals

    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,
    _

  3. #3
    Join Date
    Oct 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: changing data type parameter in qt signals

    Hi anda_skoa!

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

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: changing data type parameter in qt signals

    jees, you get the point, don't you?
    Qt Code:
    1. myclass::my_conversion_slot(int x)
    2. {
    3. unsigned long ul = static_cast<unsigned long>(x);
    4.  
    5. emit some_other_signal(ul);
    6. }
    To copy to clipboard, switch view to plain text mode 
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Oct 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: changing data type parameter in qt signals

    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.

  6. #6
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: changing data type parameter in qt signals

    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!
    Last edited by amleto; 20th November 2012 at 11:55.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: changing data type parameter in qt signals

    Quote Originally Posted by amleto View Post
    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,
    _

  8. #8
    Join Date
    Oct 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: changing data type parameter in qt signals

    Quote Originally Posted by anda_skoa View Post
    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.

    Quote Originally Posted by amleto View Post
    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.

  9. #9
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: changing data type parameter in qt signals

    sounds like a crazy homework/coursework assignment. Not sure if it's worse than banning use of STL or not...
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Replies: 2
    Last Post: 29th October 2012, 10:52
  2. Pointer parameter in signals: Memory leak?
    By AlGaN in forum Qt Programming
    Replies: 3
    Last Post: 2nd December 2010, 10:24
  3. Replies: 1
    Last Post: 16th March 2010, 15:46
  4. Replies: 2
    Last Post: 6th July 2009, 12:53
  5. Problem with connect() (enum-type as parameter)
    By alu23 in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:46

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.