Results 1 to 6 of 6

Thread: using cut(), copy(), paste()

  1. #1
    Join Date
    Dec 2007
    Posts
    9
    Thanked 1 Time in 1 Post

    Question using cut(), copy(), paste()

    Hello. I have a program which have Edit menu, where I have cut, copy and paste.
    I tried to use these menus with the following:
    Qt Code:
    1. ...
    2. connect(action_Copy,SIGNAL(triggered()),lineEdit_2,SLOT(copy()));
    3. connect(action_Copy,SIGNAL(triggered()),lineEdit_3,SLOT(copy()));
    4. ...
    To copy to clipboard, switch view to plain text mode 
    Now the copy menu works, but there is over one million connect there... How can I optimise this situation? I thinked about for cycle but I search other, better solution... Please help, thanks

  2. #2
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: using cut(), copy(), paste()

    Hey you will be calling one million "copy()" slots of line edit on each trigger of action_Copy. I think it is wrong (i might be wrong as i don't have any other info from you)

    Instead have a custom slot - say on_Copy() to be triggered by action_Copy, and in that obtain the line edit with keyboard focus. After that just call obtainedLineEdit->copy().
    Last edited by Gopala Krishna; 9th December 2007 at 08:55. Reason: updated contents
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  3. #3
    Join Date
    Dec 2007
    Posts
    9
    Thanked 1 Time in 1 Post

    Question Re: using cut(), copy(), paste()

    Quote Originally Posted by Gopala Krishna View Post
    Hey you will be calling one million "copy()" slots of line edit on each trigger of action_Copy. I think it is wrong (i might be wrong as i don't have any other info from you)

    Instead have a custom slot - say on_Copy() to be triggered by action_Copy, and in that obtain the line edit with keyboard focus. After that just call obtainedLineEdit->copy().
    But how can I resolve this?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: using cut(), copy(), paste()

    Let's say you have a class called Window which contains those line edits.

    You would begin with declaring a new custom slot:
    Qt Code:
    1. class Window : public WhatEver
    2. {
    3. Q_OBJECT // <---
    4. public:
    5. [...]
    6.  
    7. private slots:
    8. void copy(); // <---
    9. };
    To copy to clipboard, switch view to plain text mode 

    Then, instead of connecting to each line edit's copy(), you would connect to this custom slot we declared above:
    Qt Code:
    1. connect(action_Copy,SIGNAL(triggered()),this,SLOT(copy()));
    To copy to clipboard, switch view to plain text mode 

    Finally, you would implement the custom slot. More or less something like this:
    Qt Code:
    1. void Window::copy()
    2. {
    3. // get the last child widget which has focus and
    4. // try to cast it as line edit
    5. QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(focusWidget());
    6. if (lineEdit)
    7. {
    8. // it was a line edit, perform copy
    9. lineEdit->copy();
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    fnmblot (18th December 2007)

  6. #5
    Join Date
    Dec 2007
    Posts
    9
    Thanked 1 Time in 1 Post

    Lightbulb Re: using cut(), copy(), paste()

    Quote Originally Posted by jpn View Post
    Qt Code:
    1. QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(focusWidget());
    To copy to clipboard, switch view to plain text mode 
    Thanks. This is what I searched for...

  7. #6
    Join Date
    Jul 2006
    Location
    Atlanta, GA
    Posts
    86
    Thanks
    26
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: using cut(), copy(), paste()

    Awesome! I have been trying to find out how to do that for months now!
    fnmblot
    --------------------------------------
    Gee Ricky, I'm sorry your mom blew up.

Similar Threads

  1. Mac: Copy Files Build Phase and qmake...
    By kuwan in forum Qt Programming
    Replies: 4
    Last Post: 25th September 2007, 21:59
  2. copy and run a .exe file in another system
    By sabeesh in forum Installation and Deployment
    Replies: 3
    Last Post: 22nd August 2007, 11:05
  3. Copy progress bar
    By safknw in forum Newbie
    Replies: 13
    Last Post: 16th September 2006, 10:02
  4. file copy in Qt 3.3.4 ?
    By npc in forum Newbie
    Replies: 6
    Last Post: 31st March 2006, 15:43

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.