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?

How to write another Thread data in txt file?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtimerqthreadqt5c++
4 Posts 2 Posters 748 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 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.

    jsulmJ 1 Reply Last reply
    0
    • D duckrae

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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
      2
      • jsulmJ jsulm

        @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 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?

        jsulmJ 1 Reply Last reply
        0
        • D duckrae

          @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?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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

          • Login

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