Hi, I'm trying to create a signal, but I can't see the code. I'm trying to prevent reading and writing to a file at the same time with QSetting. Is there perhaps another way? Thanks.
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtWidgets>
#include "parametres.h"
#include "threadsondes.h"
#include "gainable.h"
#include "affichecons.h"
{
Q_OBJECT
public:
MainWindow
(QWidget *parent
= nullptr
);
signals:
void lectureEnCours(bool m_lecture);
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtWidgets>
#include "parametres.h"
#include "threadsondes.h"
#include "gainable.h"
#include "affichecons.h"
class MainWindow: public QWidget
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
signals:
void lectureEnCours(bool m_lecture);
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
){
connect(this, &MainWindow::lectureEnCours, &m_mainwindowThreadSondes, &ThreadSondes::onLitEnCours);
m_timer1 ->start(m_timerTemps);
connect(m_timer1, &QTimer::timeout, this, &MainWindow::lectureTemperatures);
}
void MainWindow::lectureTemperatures()
{
qDebug() << "lectureTemperature() MainWindow";
emit lectureEnCours(true);
}
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
:QWidget (parent)
{
connect(this, &MainWindow::lectureEnCours, &m_mainwindowThreadSondes, &ThreadSondes::onLitEnCours);
m_timer1 = new QTimer(this);
m_timer1 ->start(m_timerTemps);
connect(m_timer1, &QTimer::timeout, this, &MainWindow::lectureTemperatures);
}
void MainWindow::lectureTemperatures()
{
qDebug() << "lectureTemperature() MainWindow";
emit lectureEnCours(true);
}
To copy to clipboard, switch view to plain text mode
threadsondes.h
#ifndef THREADSONDES_H
#define THREADSONDES_H
#include <QThread>
#include <QObject>
#include "sondes.h"
{
Q_OBJECT
public:
ThreadSondes();
bool lecture = false;
void lectureTemperaturesEnCours();
public slots:
void onLitEnCours(bool m_lecture);
signals:
private:
DS18b20 m_threadSondesDS18b20;
void run();
};
threadsondes.cpp
[CODE]
#include "threadsondes.h"
#include <QDebug>
ThreadSondes::ThreadSondes()
{
qDebug() << "ThreadSondes";
}
void ThreadSondes::onLitEnCours(bool m_lecture)
{
lecture = m_lecture;
}
void ThreadSondes::lectureTemperaturesEnCours()
{
if (lecture == true) {
qDebug() << "lecture = " << lecture;
} else {
qDebug() << "lecture = " << lecture;
}
}
void ThreadSondes::run()
{
while (1) {
qDebug() << "run ThreadSondes()";
lectureTemperaturesEnCours();
/*m_threadSondesDS18b20.lectureSondeExt(); // on ecrite dans parametres en meme temps
m_threadSondesDS18b20.lectureSondeUnitExt();
m_threadSondesDS18b20.lectureSondeEcExt();
m_threadSondesDS18b20.lectureSondeUnitInt();
m_threadSondesDS18b20.lectureSondeEcInt();
sleep(5);*/
}
}
#ifndef THREADSONDES_H
#define THREADSONDES_H
#include <QThread>
#include <QObject>
#include "sondes.h"
class ThreadSondes: public QThread
{
Q_OBJECT
public:
ThreadSondes();
bool lecture = false;
void lectureTemperaturesEnCours();
public slots:
void onLitEnCours(bool m_lecture);
signals:
private:
DS18b20 m_threadSondesDS18b20;
void run();
};
threadsondes.cpp
[CODE]
#include "threadsondes.h"
#include <QDebug>
ThreadSondes::ThreadSondes()
{
qDebug() << "ThreadSondes";
}
void ThreadSondes::onLitEnCours(bool m_lecture)
{
lecture = m_lecture;
}
void ThreadSondes::lectureTemperaturesEnCours()
{
if (lecture == true) {
qDebug() << "lecture = " << lecture;
} else {
qDebug() << "lecture = " << lecture;
}
}
void ThreadSondes::run()
{
while (1) {
qDebug() << "run ThreadSondes()";
lectureTemperaturesEnCours();
/*m_threadSondesDS18b20.lectureSondeExt(); // on ecrite dans parametres en meme temps
m_threadSondesDS18b20.lectureSondeUnitExt();
m_threadSondesDS18b20.lectureSondeEcExt();
m_threadSondesDS18b20.lectureSondeUnitInt();
m_threadSondesDS18b20.lectureSondeEcInt();
sleep(5);*/
}
}
To copy to clipboard, switch view to plain text mode
[/CODE]
Bookmarks