Results 1 to 13 of 13

Thread: one signal to two slots for reading and logging in a file

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: one signal to two slots for reading and logging in a file

    Slot is normal class method. So in body call some another method with QByteArray argument to save data to file.
    These are the basics of C++.

  2. The following user says thank you to Lesiok for this useful post:

    QJak (16th April 2018)

  3. #2
    Join Date
    Dec 2016
    Posts
    30
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: one signal to two slots for reading and logging in a file

    thanks again. you mean i call saving function from body of slot? (i need to do two works (1-reading and processing 2-reading and writing in a file) together like tread.
    please explain more

  4. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: one signal to two slots for reading and logging in a file

    Yes. In slot You need :

    1. Read data from port.
    2. Process data.
    3. Write data in a file.

    Steps 2 and 3 can be swapped.

  5. #4
    Join Date
    Dec 2016
    Posts
    30
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: one signal to two slots for reading and logging in a file

    thanks but processing and writing after that is too slow. i need to do 2 jobs in the same time
    is this work correct to emit a signal after reading like this:
    i define a signal in name of : signal_saving(QByteArray) and connect this signal to the second slot below
    then define 2 slots: slot1_readingAndProcessing() , slot2_saving(QByteArray)
    after connecting signal_saving(QByteArray) to slot2_saving(QByteArray) i emit this signal after reading data in body of first slot. imean:
    slot1_readingAndProcessing()
    {
    reading data and put in QByteArray
    emit signal_saving(QBytArray)
    then processing
    }


    is this correct?

  6. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: one signal to two slots for reading and logging in a file

    Yes, this is correct under one condition : connection to slot2_saving is in Qt::QueuedConnection. In Qt:irectConnection emiting a signal is equivalent to calling the method. Read documentation.

  7. The following user says thank you to Lesiok for this useful post:

    QJak (16th April 2018)

  8. #6
    Join Date
    Dec 2016
    Posts
    30
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: one signal to two slots for reading and logging in a file

    this way has not my desier result (working paralel). please help me

  9. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,329
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: one signal to two slots for reading and logging in a file

    ...thanks but processing and writing after that is too slow. i need to do 2 jobs in the same time...

    ...working paralel...

    please help me
    Please explain why you insist this must be a parallel operation (you say so here and in your other posts). What is your "processing" that makes it so slow? And writing a small amount of data to a log file should be very fast, unless you are opening and closing the file for every write.

    Based on what you are asking and how you are asking it, I am not sure you understand enough to write a multi-threaded application that will work correctly.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 29
    Last Post: 24th January 2017, 12:30
  2. Replies: 0
    Last Post: 20th July 2013, 03:07
  3. Signal/Slots, Where can i use it?
    By Tio in forum Newbie
    Replies: 2
    Last Post: 25th May 2010, 01:36
  4. Signal and Slots
    By waynew in forum Newbie
    Replies: 3
    Last Post: 20th November 2009, 03:50
  5. Logging to a file and using same model for diff views
    By steg90 in forum Qt Programming
    Replies: 4
    Last Post: 10th May 2007, 23:16

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
  •  
Qt is a trademark of The Qt Company.