Page 1 of 2 12 LastLast
Results 1 to 20 of 36

Thread: QSignalMapper

  1. #1
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Smile QSignalMapper

    hi all

    i want to make a multi-stream http proxy. i faced to a problem.
    my problem is about "look up host"
    i used QHostInfo to do this.(function LookupHost(...))
    as we know this function emit a signal that have one parameter (QHostInfo &)
    but i want connect each stream look up to it's own function
    in other words i want this slot:
    Qt Code:
    1. void LookUpResult(QHostInfo @hi , int id)
    To copy to clipboard, switch view to plain text mode 
    that id is the identifier of a specific stream.
    how to implement this??
    please help

    thanks in advance.
    Life is about making the right decisions and moving on.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    506
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSignalMapper

    Hi, I don't think you can do that with QSignalMapper.
    As a (little bitugly) work-around you can connect all signals to one slot and use sender() to check which stream sent the signal.

    Ginsengelf
    Last edited by Ginsengelf; 5th November 2012 at 08:12. Reason: spelling corrections

  3. #3
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: QSignalMapper

    hi Ginsengelf
    thanks for replying

    please explain more. i do not understand what your mean !

    thanks again...
    Life is about making the right decisions and moving on.

  4. #4
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: QSignalMapper

    help me!!!
    i do not take my answer.
    please offer me a solution... or a new approach or ...

    regards
    Life is about making the right decisions and moving on.

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

    Default Re: QSignalMapper

    Quote Originally Posted by Ali Reza View Post
    hi all

    i want to make a multi-stream http proxy. i faced to a problem.
    my problem is about "look up host"
    i used QHostInfo to do this.(function LookupHost(...))
    as we know this function emit a signal that have one parameter (QHostInfo &)
    but i want connect each stream look up to it's own function
    in other words i want this slot:
    Qt Code:
    1. void LookUpResult(QHostInfo @hi , int id)
    To copy to clipboard, switch view to plain text mode 
    that id is the identifier of a specific stream.
    how to implement this??
    please help

    thanks in advance.
    just copy the example in the docs

    qsignalmapper
    Last edited by amleto; 10th November 2012 at 21:05.
    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.

  6. #6
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: QSignalMapper

    this link get me 404 not found !!!
    Life is about making the right decisions and moving on.

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

    Default Re: QSignalMapper

    changed it.

    not sure exactly what you're trying to do, though. There needs to be something that knows the id to use, but you dont show where that is in your code
    Last edited by amleto; 10th November 2012 at 21:16.
    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.

  8. #8
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: QSignalMapper

    how to implement with QSignalMapper ?? (if possible)
    Life is about making the right decisions and moving on.

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

    Default Re: QSignalMapper

    Why do you want

    void LookUpResult(QHostInfo hi , int id)

    when id = hi.lookupId()?*

    *I believe this is true but I'm not certain.
    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.

  10. #10
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: QSignalMapper

    i want to implement a multi stream HTTP proxy that accept many connections from the browser.
    my proxy must look up IP address of the host that specified by each TCP stream (for each http request from browser)
    thus i must look up the ip for each stream concurrently
    i used QHostInfo ( method LookUpHost() ).
    now i want connect the result of this function to my customized slot:
    Qt Code:
    1. void LookUpResult(QHostInfo @hi , int id)
    To copy to clipboard, switch view to plain text mode 
    how ???

    thanks
    Life is about making the right decisions and moving on.

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

    Default Re: QSignalMapper

    well, you were given the id earlier when you called lookupHost. so save 'id', and when you receive HostInfo you will be ready to call that slot.
    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.

  12. #12
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: QSignalMapper

    please explain to me by coding. i do not understand your mean.
    thanks
    Life is about making the right decisions and moving on.

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

    Default Re: QSignalMapper

    tell me, what is the difference between

    hostinfo.lookupId() and your 'int id' in void LookUpResult(QHostInfo @hi , int id)??

    I say there is no difference!

    Therefore you don't need
    Qt Code:
    1. void LookUpResult(QHostInfo @hi , int id)
    To copy to clipboard, switch view to plain text mode 
    because you can use
    Qt Code:
    1. void LookUpResult(QHostInfo hi)
    2. {
    3. int id = hi.lookupId();
    4. // ...
    5. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by amleto; 17th November 2012 at 16:38.
    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.

  14. #14
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: QSignalMapper

    sorry for my bad English.

    my 'id' is a identifier of a stream that established by a internet browser.
    i don't know the hostinfo.lookuoid() is what !
    please tell me the above function what returns.

    thanks


    Added after 5 minutes:


    thanks dear amleto
    i understand what you say
    my problem solved .

    thanks very very much...
    Last edited by Ali Reza; 18th November 2012 at 09:20.
    Life is about making the right decisions and moving on.

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

    Default Re: QSignalMapper

    sorry, finally I think I understand your problem. I think what I suggested above might not work as you want.

    Qt Code:
    1. class MyMapper : QObject
    2. {
    3. // Q_OBJECt etc
    4.  
    5. public:
    6. MyMapper(int id) : id_(id) {}
    7.  
    8.  
    9. public slots:
    10. void myResultLookup(QHostInfo info)
    11. {
    12. //...
    13. resultLookup(info, id_);
    14. deleteLater(); // this object no longer needed?
    15. }
    16.  
    17. private:
    18. int id_;
    19.  
    20. };
    21.  
    22. void YourMethod()
    23. {
    24.  
    25. int streamId = ...;
    26. QString hostname = ...;
    27. MyMapper* mapper = new MyMapper(streamId);
    28. QHostInfo::lookupHost(hostname, mapper, SLOT(myResultLookup(QHostInfo)));
    29. }
    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.

  16. #16
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: QSignalMapper

    thanks again ...
    solved !


    Added after 4 minutes:


    hey amleto
    excuse me, another problem
    is there any way to IP caching in Qt Creator ?
    Last edited by Ali Reza; 19th November 2012 at 08:54.
    Life is about making the right decisions and moving on.

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

    Default Re: QSignalMapper

    not sure. probably time for a new thread!
    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.

  18. #18
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: QSignalMapper

    Hey amleto
    *** NOT SOLVED ***
    your snipped code about Host look up is wrong.
    in definition of myResultLookup from Mapper class ,you call resultLookup. but this function is member of another class!!
    what can i do?

    regards
    Last edited by Ali Reza; 25th November 2012 at 16:11. Reason: spelling corrections
    Life is about making the right decisions and moving on.

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

    Default Re: QSignalMapper

    My code isn't wrong, it's just not complete. That function comes from your code. you figure out how to pass it in
    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.

  20. #20
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: QSignalMapper

    excuse me !
    i did not understand
    1.you define a new class that named "MyMapper" that inherits "QObject". but this definition get me the following error:
    " 'QObject' is an inaccessible base of 'MyMapper' ".
    2.you call function "resultLookup(info, id_);" in line 13 in your code. but this function is not accessible here (this function is member of another class)

    plz tell me how your code is right ?

    thanks alot dear amleto !
    Life is about making the right decisions and moving on.

Similar Threads

  1. qSignalMapper gets no output
    By saman_artorious in forum Qt Programming
    Replies: 10
    Last Post: 31st July 2012, 09:00
  2. QSignalMapper
    By axisdj in forum Newbie
    Replies: 6
    Last Post: 16th September 2010, 01:52
  3. QSignalMapper and argument problems
    By harmodrew in forum Newbie
    Replies: 14
    Last Post: 7th August 2010, 19:20
  4. help with QSignalMapper and actions
    By andreime in forum Newbie
    Replies: 1
    Last Post: 9th August 2009, 18:24
  5. ? about QSignalMapper
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 13th January 2008, 21:21

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.