Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Polish
  4. Problem z Qtimer

Problem z Qtimer

Scheduled Pinned Locked Moved Polish
4 Posts 2 Posters 1.8k 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.
  • M Offline
    M Offline
    mike23
    wrote on last edited by
    #1

    Witam!
    mam problem z timerem, potrzebuję żeby funkcja Petla() wykonywała się co sekundę starałem się zrobić to w ten sposób:

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    QTimer *timer = new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(Petla(QString,QString)));
    timer->start(1000);
    ui->setupUi(this);
    }@

    w funkcji SendMessage znajduje się funkcja Petla() która powinna się wykonywać co sekunde

    @void MainWindow::SendMessage(QString to, QString text)
    {
    Petla(ui->uriEdit->text(), ui->textEdit->toPlainText());
    }@

    Gdzie tkwi błąd? Czy w funkcji petla oprócz ciała funkcji powinny tkwić jakieś dodatkowe parametry dotyczące timera?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Błędów w tym kodzie kilka, ale głównie to nie potrzebujesz przecież żadnych argumentów w SendMessage. Wykasuj "QString to, QString text" z definicji i deklaracji tej funkcji, a także z połączenia sygnału i slotu.

      (Z(:^

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mike23
        wrote on last edited by
        #3

        dzięki, już sobie z tym poradziłem. Mam jeszcze pytanie, w jaki sposób zatrzymać timer? np żeby zatrzymał się po pewnej ilości wykonanych pętli

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Użyj "QTimer::Stop()":http://qt-project.org/doc/qt-5/qtimer.html#stop. Ilość powtórzeń pętli musisz zliczyć sam, QTimer nie ma daje takich możliwości.

          (Z(:^

          1 Reply Last reply
          0

          • Login

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