Results 1 to 5 of 5

Thread: Just launch a function and do not append to it?

  1. #1
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation Just launch a function and do not append to it?

    I am not sure you got me....
    What I need is to just launch a function like it was a separate program.
    For example, if a timer was connected to a slot like this:
    Qt Code:
    1. void slot_1(){
    2. while(1){
    3. sleep(10);
    4. }
    5. }
    To copy to clipboard, switch view to plain text mode 
    the program would stack! I don't want it to 'stack'. I want to go forward even if such a function was called. Is this possible?
    To be more realistic, I have a system command that reaches some files from the internet, and it may be late sometime and make my program unresponsive to clicks etc because of this....

    PS: I though that QTimer::SingleShot was for that job but it does append to the slot unfortunately, so, after all, what's the difference between
    Qt Code:
    1. QTimer::singleShot(0, this, SLOT(function()));
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. function();
    To copy to clipboard, switch view to plain text mode 

    Thanks for any answers!
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Just launch a function and do not append to it?

    I think what you need is to run the function in separate thread. Search for examples on Qt Centre wiki or threads on forum.

  3. The following user says thank you to stampede for this useful post:

    hakermania (6th July 2011)

  4. #3
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Just launch a function and do not append to it?

    Hm, thank google wasn't very helpful....
    Should I use QThread or QObject? This wasn't clear too...
    Do I have to create my own classes? Can I avoid this? I need something simple, like:
    Qt Code:
    1. QObject object;
    2. object.setFunction(MainWindow::MyFunction_that_I_want_to_be_launched());
    3. object.run
    4. //more code here that will be executed without waiting the MyFunction_that_I_want_to_be_launched() to finish running
    To copy to clipboard, switch view to plain text mode 

    I don't know what are they talking about producers and consumers....
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  5. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Just launch a function and do not append to it?

    If you want to run only one function, take a look at QtConcurrent module and QtConcurrent::run method.
    I don't know what are they talking about producers and consumers....
    Because it's a standard example used to explain multithreading concepts.

  6. The following user says thank you to stampede for this useful post:

    hakermania (8th July 2011)

  7. #5
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Just launch a function and do not append to it?

    Yeah! This did the trick man! Thanks
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

Similar Threads

  1. Can't see any text append in UI?
    By SamT in forum Qt Programming
    Replies: 3
    Last Post: 9th April 2011, 12:27
  2. Append file
    By mvbhavsar in forum Newbie
    Replies: 3
    Last Post: 10th February 2011, 08:38
  3. Cannot append to QFile using QIODevice::Append
    By philwinder in forum Qt Programming
    Replies: 4
    Last Post: 17th November 2008, 09:09
  4. QVector - Append
    By krishbhala in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2007, 10:50
  5. QTextEdit::append help
    By tho97 in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2007, 07:10

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.