السلام عليكم ورحمة الله وبركاتة
في البداية انا جديد على لغة الـ C++ ..
عمل برنامج وضيفته انه إذا أتى الماوس(مؤشر الفأرة) على زر يقوم هذا الزر بالإنتقال(pos) إلى الأعلى قليلاً وإذا ابتعد الماوس عن الزر يرجع الزر إلى مكانه السابق
وقمت بإنشاء الكود من خلال QT Creator .. قمت بالإستعانه بـ Thread ..
هذه ملفات المشروع :

هذه الأكود لكل ملف عدا ملف الـui :
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <mythread.h>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
bool buttonsUnderMuse();
void movebuttonToUp();
void movebuttonToDown();
private:
Ui::Widget *ui;
};
#endif // WIDGET_Hwidget.cpp
#include "widget.h"
#include "ui_widget.h"
#include <QPropertyAnimation>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
bool Widget::buttonsUnderMuse()
{
return ui->pushButton->underMouse();
}
void Widget::movebuttonToUp()
{
QPropertyAnimation *B_one = new QPropertyAnimation(ui->pushButton, "pos");
B_one->setDuration(1200);
B_one->setEasingCurve(QEasingCurve::InBack);
B_one->setStartValue(QPoint(0,260));
B_one->setEndValue(QPoint(0,200));
B_one->start();
}
void Widget::movebuttonToDown()
{
QPropertyAnimation *B_one = new QPropertyAnimation(ui->pushButton, "pos");
B_one->setDuration(1200);
B_one->setEasingCurve(QEasingCurve::InBack);
B_one->setStartValue(QPoint(0,200));
B_one->setEndValue(QPoint(0,260));
B_one->start();
}وهذا الملفات الخاصة بالـ Thread :
mythread.h
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QThread>
#include <widget.h>
class myThread : public QThread
{
Q_OBJECT
public:
explicit myThread(QObject *parent = 0);
void run();
bool getBottnUnderMuse();
signals:
public slots:
};
#endif // MYTHREAD_Hmythread.cpp
#include "mythread.h"
#include "widget.h"
myThread::myThread(QObject *parent) :
QThread(parent)
{
}
void myThread::run()
{
while(true)
{
if(getBottnUnderMuse() == true)
{
MovebuttonToUp; // I get error here ... error: 'MovebuttonToUp' was not declared in this scope
}
else
{
movebuttonToDow; // I get error here ... error: 'movebuttonToDow' was not declared in this scope
}
msleep(200);
}
}
bool myThread::getBottnUnderMuse()
{
return buttonsUnderMuse; // I get error here ... error: 'buttonsUnderMuse' was not declared in this scope
}-------------------------------
المشكلة التي واجهتني هي اني لا استطيع الوصول من خلال "mythread.cpp" إلى الدوال الموجودة في ملف الهيدرا "widget.h" رغم اني وضعت ملف الهيدرا "widget.h" ضمن الـ include ..
اعتقد ان المشكلة واضحه
وكذلك نقطة آخرى .. ربما اكون قد عملت هذا البرنامج بطريقة معقدة او ما شابه مثلاً .. البرنامج لا يحتاج إلى Thread بينما قمت بإستعمال ثريد لعمل مثل هذه الوظيفة .. لذلك لا مانع من طريق اخرى
وشكراً لحسن القراءة