#include <QtWidgets>#include "counter.h"void Counter::setValue(const QString& value){ QWidget* wgt2 = new QWidget; Counter* ptxt2 = new Counter; QVBoxLayout* pvbxLayout2 = new QVBoxLayout; pvbxLayout2->addWidget(ptxt2); wgt2->setLayout(pvbxLayout2); wgt2->setAttribute(Qt::WA_ShowWithoutActivating); wgt2->setAttribute(Qt::WA_DeleteOnClose); wgt2->show();}int main(int argc, char** argv){ QApplication app(argc, argv); QWidget* wgt = new QWidget; Counter* ptxt = new Counter; QObject::connect(ptxt, SIGNAL(textChanged(const QString&)), ptxt, SLOT(setValue(const QString&))); QVBoxLayout* pvbxLayout = new QVBoxLayout; pvbxLayout->addWidget(ptxt); wgt->setLayout(pvbxLayout); wgt->setWindowFlags(wgt->windowFlags() | Qt::WindowStaysOnTopHint); wgt->setAttribute(Qt::WA_DeleteOnClose); wgt->show(); int x = wgt->x(); int y = wgt->y(); return app.exec();}
#ifndef COUNTER_H#define COUNTER_H#include <QObject>#include <QtWidgets>class Counter : public QLineEdit{ Q_OBJECTpublic slots: void setValue(const QString&);};#endif
#include <QtWidgets>#include "counter.h"void Counter::setValue(const QString& value){ emit myTextChanged(const &QString value, int& x, int& y);}void Counter::setValue2(const QString& value, int&, int&){QWidget* wgt2 = new QWidget;Counter* ptxt2 = new Counter;QVBoxLayout* pvbxLayout2 = new QVBoxLayout;pvbxLayout2->addWidget(ptxt2);wgt2->setLayout(pvbxLayout2);wgt2->setAttribute(Qt::WA_ShowWithoutActivating);wgt2->setAttribute(Qt::WA_DeleteOnClose);wgt2->move(x,y);wgt2->show();}int main(int argc, char** argv){ QApplication app(argc, argv); QWidget* wgt = new QWidget; Counter* ptxt = new Counter; QObject::connect(ptxt, SIGNAL(textChanged(const QString&)), ptxt, SLOT(setValue(const QString&))); QObject::connect(ptxt, SIGNAL(myTextChanged(const QString&, int&, int&)), ptxt, SLOT(setValue2(const QString&, int&, int&))); QVBoxLayout* pvbxLayout = new QVBoxLayout; pvbxLayout->addWidget(ptxt); wgt->setLayout(pvbxLayout); wgt->setWindowFlags(wgt->windowFlags() | Qt::WindowStaysOnTopHint); wgt->setAttribute(Qt::WA_DeleteOnClose); wgt->show(); int x = wgt->x(); int y = wgt->y(); return app.exec();}
#ifndef COUNTER_H#define COUNTER_H#include <QObject>#include <QtWidgets>class Counter : public QLineEdit{ Q_OBJECTpublic slots: void setValue(const QString&); void setValue2(const QString&, int&, int&);signals: void myTextChanged(const QString&, int&, int&);};#endif
C++ (Qt)void Counter::textChanged( const QString & ){ int x = this->window()->x(): int y = this->window()->y(): ...}
C++ (Qt)// файл main.cppint theX, theY; // объявляете нужные переменные глобальными void main( ..) { ... theX = MyCalcX(...); // вычисляете значения theY = MyCalcY(...); ...}
C++ (Qt)// файл Counter.cpp extern int theX; // или объявить их в Counter.h или любом хедере видимом отсюдаextern int theY; void Counter::textChanged( const QString & ){ ...