Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to write another Thread data in txt file?
QtWS25 Last Chance

How to write another Thread data in txt file?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtimerqthreadqt5c++
4 Posts 2 Posters 746 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    duckrae
    wrote on 19 Oct 2021, 07:23 last edited by
    #1

    Hello.
    I want to write data from another thread in txt file.
    Text files will be named currentTime() and created periodically every minute.
    So, Txt file made very well every minute using QTimer, but In Txt file, content is null.
    Of course this result is correct. Because i didn't connect data from another Thread.
    How to connect or send data from another thread to QTimer make the txt file every minute?
    For example, another thread get data every second and QTimer make txt file every minute.
    Ideally, another thread get 60 data in minute and one text file made in minute.
    I want to write 60 data to txt file one cycle.

    J 1 Reply Last reply 19 Oct 2021, 07:27
    0
    • D duckrae
      19 Oct 2021, 07:23

      Hello.
      I want to write data from another thread in txt file.
      Text files will be named currentTime() and created periodically every minute.
      So, Txt file made very well every minute using QTimer, but In Txt file, content is null.
      Of course this result is correct. Because i didn't connect data from another Thread.
      How to connect or send data from another thread to QTimer make the txt file every minute?
      For example, another thread get data every second and QTimer make txt file every minute.
      Ideally, another thread get 60 data in minute and one text file made in minute.
      I want to write 60 data to txt file one cycle.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 19 Oct 2021, 07:27 last edited by
      #2

      @duckrae Move the one minute timer to the thread. When the timer times out emit a signal in the thread passing the collected text as signal parameter. Connect this signal to a slot and write the file in that slot.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply 19 Oct 2021, 08:05
      2
      • J jsulm
        19 Oct 2021, 07:27

        @duckrae Move the one minute timer to the thread. When the timer times out emit a signal in the thread passing the collected text as signal parameter. Connect this signal to a slot and write the file in that slot.

        D Offline
        D Offline
        duckrae
        wrote on 19 Oct 2021, 08:05 last edited by
        #3

        @jsulm Thanks for answer. this is another question. if i start qtimer like this

        QTimer *timer = new QTimer(this)
        timer->start(60000);
        

        the time start not now but one minute left.
        I want to start QTimer now -> one minute -> one minute
        but now code one minute -> one minute -> one minute.
        How can I handle it?

        J 1 Reply Last reply 19 Oct 2021, 08:07
        0
        • D duckrae
          19 Oct 2021, 08:05

          @jsulm Thanks for answer. this is another question. if i start qtimer like this

          QTimer *timer = new QTimer(this)
          timer->start(60000);
          

          the time start not now but one minute left.
          I want to start QTimer now -> one minute -> one minute
          but now code one minute -> one minute -> one minute.
          How can I handle it?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 19 Oct 2021, 08:07 last edited by
          #4

          @duckrae said in How to write another Thread data in txt file?:

          How can I handle it?

          Simply emit the signal:

          QTimer *timer = new QTimer(this)
          timer->start(60000);
          emit myTimeoutSignal(text);
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          1/4

          19 Oct 2021, 07:23

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved