I have encountered some problem that I seem not be able to solve. It may be some silly mistake. I have a class that runs another class's method in a separate QThread 5000msec after the method fires a signal. At least this would be the idea but this is not happening.
#ifndef MOVEME_MPOINTER_HPP
#define MOVEME_MPOINTER_HPP
#include <Windows.h>
#include <WindowsX.h>
#include <QSystemTrayIcon>
#include <QDesktopWidget>
#include <QApplication>
#include <QMainWindow>
#include <QMessageBox>
#include <QByteArray>
#include <QAction>
#include <QCursor>
#include <QThread>
#include <QTimer>
#include <QDebug>
#include <QMenu>
#include <QIcon>
#include <QRect>
#include "worker.hpp"
namespace Ui {
class MoveMe_MPointer;
}
class MoveMe_MPointer : public QMainWindow
{
Q_OBJECT
public:
explicit MoveMe_MPointer(QWidget *parent = 0);
~MoveMe_MPointer();
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result);
public slots:
void resetTimer();
void closeApplication();
private:
QSharedPointer<QIcon> icon;
QSharedPointer<QSystemTrayIcon> systemtray;
QSharedPointer<QThread> workerThread;
QSharedPointer<Worker> workerObject;
QSharedPointer<QTimer> workerTimer;
QSharedPointer<QCursor> cursor;
};
#endif // MOVEME_MPOINTER_HPP
The implementation of the relevant methods are as follows:
MoveMe_MPointer::MoveMe_MPointer(QWidget *parent) : QMainWindow(parent) {
icon = QSharedPointer<QIcon>(new QIcon("://appicon"));
systemtray = QSharedPointer<QSystemTrayIcon>(new QSystemTrayIcon);
// Create cursor
cursor = QSharedPointer<QCursor>(new QCursor(Qt::ForbiddenCursor));
systemtray->setIcon(*icon.data());
systemtray->setVisible(true);
workerThread = QSharedPointer<QThread>(new QThread());
workerObject = QSharedPointer<Worker> (new Worker ());
workerObject->setX(100);
workerObject->setY(100);
workerObject->moveToThread(workerThread.data());
workerTimer = QSharedPointer<QTimer>(new QTimer());
QObject::connect(workerThread.data(), SIGNAL(started()), workerObject.data(), SLOT(Work()));
QObject::connect(workerTimer.data(), SIGNAL(timeout()), workerObject.data(), SLOT(Work()));
QObject::connect(workerObject.data(), SIGNAL(Done()), this, SLOT(resetTimer()));
RegisterHotKey((HWND) winId(), 0, MOD_CONTROL, 0x51);
RegisterHotKey((HWND) winId(), 1, MOD_CONTROL | MOD_SHIFT, 0x4D);
}
void MoveMe_MPointer::resetTimer() {
qDebug() << "START";
workerTimer->start(5000);
qDebug() << "STOP";
}
The underlying class:
#ifndef WORKER_HPP
#define WORKER_HPP
#include <Windows.h>
#include <QSharedPointer>
#include <QMouseEvent>
#include <QObject>
#include <QCursor>
#include <QThread>
#include <QDebug>
class Worker : public QObject
{
Q_OBJECT
int x;
int y;
bool stop;
public:
explicit Worker(QObject *parent = 0);
void setX(const int x);
void setY(const int y);
void Stop();
signals:
void Done();
public slots:
void Work();
private:
void doWork();
};
#endif // WORKER_HPP
With the implementation as follows:
#include "worker.hpp"
Worker::Worker(QObject *parent) : QObject(parent) {
stop = false;
}
void Worker::setX(const int x) {
this->x = x;
}
void Worker::setY(const int y) {
this->y = y;
}
void Worker::Stop() {
stop = true;
}
void Worker::Work() {
doWork();
}
void Worker::doWork() {
int _x = 50;
INPUT input;
ZeroMemory(&input, sizeof(input));
input.type = INPUT_MOUSE;
input.mi.mouseData = 0;
input.mi.dwFlags = MOUSEEVENTF_MOVE;
for (int dx = 0; dx < _x && !stop; ++dx) {
input.mi.dx = +1;
input.mi.dy = +1;
SendInput(1, &input, sizeof(input));
QThread::msleep(10);
}
QThread::msleep(100);
for (int dx = 0; dx < _x && !stop; ++dx) {
input.mi.dx = -1;
input.mi.dy = -1;
SendInput(1, &input, sizeof(input));
QThread::msleep(10);
}
QThread::msleep(100);
emit Done();
}
Whenever my application receives the Done signal my resetTimer slot gets executed but the interesting part is. It times out immediately and does not wait even a second. What am i missing?
Related
I have created a project and a basic app where there is a ui that pops up for users to enter data and then the data is uploaded to a firebase database. When I attempt to run the app the ui appears and i can enter in the data like in this image:
Here is my main.cpp:
#include "checkinapp.h"
#include "databasehandler.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
checkinapp w;
w.show();
DatabaseHandler dbhandler;
return a.exec();
}
The app gets stuck on w.show(). How can i make the submit button end w.show() and run the next line DatabaseHandler dbhandler
here is my checkinapp.h:
#ifndef CHECKINAPP_H
#define CHECKINAPP_H
#include <iostream>
#include <QMainWindow>
#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QMessageBox>
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
QT_BEGIN_NAMESPACE
namespace Ui { class checkinapp; }
QT_END_NAMESPACE
class checkinapp : public QMainWindow
{
Q_OBJECT
public:
checkinapp(QWidget *parent = nullptr);
~checkinapp();
private slots:
void on_happy_valueChanged(int value);
void on_hungry_valueChanged(int value);
void on_sleep_valueChanged(int value);
void on_stress_valueChanged(int value);
void on_male_toggled(bool checked);
void on_female_toggled(bool checked);
void on_other_toggled(bool checked);
void on_help_toggled(bool checked);
void on_pushButton_clicked();
private:
Ui::checkinapp *ui;
};
#endif // CHECKINAPP_H
checkinapp.cpp:
#include "checkinapp.h"
#include "ui_checkinapp.h"
#include "databasehandler.h"
#include "global_objects.hpp"
#include <QNetworkRequest>
#include <QDebug>
#include <QJsonDocument>
#include <QVariantMap>
#include <iostream>
using namespace std;
checkinapp::checkinapp(QWidget *parent)
: QMainWindow(parent),
ui(new Ui::checkinapp)
{
ui->setupUi(this);
}
checkinapp::~checkinapp()
{
if(help == 1)
{
//delete ui;
}
if(help == 1)
{
cout << "help";
}
}
void checkinapp::on_happy_valueChanged(int value)
{
happy = value;
}
void checkinapp::on_hungry_valueChanged(int value)
{
hungry = value;
}
void checkinapp::on_sleep_valueChanged(int value)
{
tired = value;
}
void checkinapp::on_stress_valueChanged(int value)
{
stressed = value;
}
void checkinapp::on_male_toggled(bool checked)
{
if(checked == true)
{
gender = 0;
}
}
void checkinapp::on_female_toggled(bool checked)
{
if(checked == true)
{
gender = 1;
}
}
void checkinapp::on_other_toggled(bool checked)
{
if(checked == true)
{
gender = 2;
}
}
void checkinapp::on_help_toggled(bool checked)
{
if(checked == true)
{
help = 1;
}
}
void checkinapp::on_pushButton_clicked()
{
submitted = true;
if(submitted==true)
{
cout <<submitted;
}
//delete ui;
}
databasehandler.h:
#ifndef DATABASEHANDLER_H
#define DATABASEHANDLER_H
#include <checkinapp.h>
#include <QObject>
#include <QWidget>
#include <QNetworkAccessManager>
#include <QNetworkReply>
class DatabaseHandler : public QObject
{
Q_OBJECT
public:
explicit DatabaseHandler(QObject *parent = nullptr);
~DatabaseHandler();
public slots:
void networkReplyReadyRead();
signals:
private:
QNetworkAccessManager * m_networkManager;
QNetworkReply * m_networkReply;
};
#endif // DATABASEHANDLER_H
databasehandler.cpp:
#include "checkinapp.h"
#include "databasehandler.h"
#include "global_objects.hpp"
#include <QNetworkRequest>
#include <QDebug>
#include <QJsonDocument>
#include <QVariantMap>
#include <iostream>
DatabaseHandler::DatabaseHandler(QObject *parent) : QObject(parent)
{
m_networkManager = new QNetworkAccessManager ( this );
QVariantMap newUser;
newUser[ "Stress" ] = QString::number(stressed);
newUser[ "Sleep" ] = QString::number(tired);
newUser[ "Hungry" ] = QString::number(hungry);
newUser[ "Happy" ] = QString::number(happy);
newUser[ "Grade" ] = QString::number(grade);
newUser[ "Date" ] = "1/10/21";
newUser[ "Gender" ] = QString::number(gender);
newUser[ "Aid" ] = QString::number(help);
QJsonDocument jsonDoc = QJsonDocument::fromVariant( newUser );
QNetworkRequest newUserRequest( QUrl( "url/User.json"));
newUserRequest.setHeader( QNetworkRequest::ContentTypeHeader, QString( "application/json" ));
m_networkManager->post( newUserRequest, jsonDoc.toJson() );
}
DatabaseHandler::~DatabaseHandler()
{
m_networkManager->deleteLater();
}
void DatabaseHandler::networkReplyReadyRead()
{
//qDebug() << m_networkReply->readAll();
}
Okay, I think you have some confusion. w.show() makes the window appear. That's it. Execution continues all the way to your a.exec().
What you need to do is have your window tell your DatabaseHandler when it's time to grab values and do an update. The Qt way is to set up a signal. I find those to kind of be a pain, so I use dependency injection. That is, I'd create the handler earlier in main but NOT have the constructor do all that. Make a method. Then pass a reference to the handler in the constructor of the window.
Then when the button is clicked, call a method on the handler to do its job. After that, you can close the app if you want.
I am try to do some offscreen rendering jobs in Qt5.3 and I want to use QOpenGLFramebufferObject::toImage to output each pictures(I want to output a few pictures when render() draws different things).
Following the instructions of this, I succeeded in offscreen rendering my first pic and outputing it. So to future on, I write an example as the following code and here is a package in Google. I can get the first fbo content(and its output file correctly, but from the second time, the fbo was not re-render() and it always output the same pictures).
So I want to know what should I do after I finish one time offscreen render to make sure the next time would be correct in qt? Or is there anyone could tell me how to set animation correctly in QOffscreenSurface?
qtestofffscreen.h:
#ifndef QTESTOFFSCREEN_H
#define QTESTOFFSCREEN_H
#include <QOffscreenSurface>
#include <QWindow>
#include <QtGui/QOpenGLFunctions_3_3_Core>
#include <QImage>
#include <QGLFramebufferObject>
#include <QOpenGLPaintDevice>
#include <QOpenGLFunctions>
#include <QMutex>
#include <QMutexLocker>
class QTestOffScreen : public QOffscreenSurface,
protected QOpenGLFunctions_3_3_Core
{
Q_OBJECT
public:
explicit QTestOffScreen(
QScreen* targetScreen = nullptr,
const QSize& size = QSize (1, 1));
~QTestOffScreen();
virtual void render();
virtual void initialize();
void renderNow();
void setAnimating(bool animating);
bool event(QEvent *) override;
void renderLater();
int counts;
private:
QGLFramebufferObject *fbo;
bool m_animating;
bool m_update_pending;
QOpenGLContext *m_context;
QOpenGLPaintDevice *m_device;
QSize m_size;
QMutex mutex;
signals:
void doneImg(int index);
};
#endif // QTESTOFFSCREEN_H
qtestofffscreen.cpp:
#include "qtestoffscreen.h"
#include <QTime>
#include <QDebug>
#include <QCoreApplication>
#include <QOpenGLFramebufferObject>
QTestOffScreen::QTestOffScreen(QScreen *targetScreen,
const QSize &size):
QOffscreenSurface(targetScreen),
m_size(size),
fbo(Q_NULLPTR),
m_context(Q_NULLPTR),
m_device(Q_NULLPTR),
counts(100)
{
requestedFormat().setVersion(3,3);
setFormat(requestedFormat());
create();
m_context = new QOpenGLContext(this);
m_context->setFormat(format());
if (m_context->create())
{
m_context->makeCurrent(this);
m_context->functions()->initializeOpenGLFunctions();
}else
{
delete m_context;
m_context = Q_NULLPTR;
throw ("Still wrong here");
}
//To make sure m_context was initialized
//in first time entering renderNow()
delete m_context;
m_context = Q_NULLPTR;
}
QTestOffScreen::~QTestOffScreen()
{
delete m_context;
delete m_device;
if (fbo)
delete fbo;
}
void QTestOffScreen::render()
{
glClearColor(0.0f,0.0f,0.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
| GL_TEXTURE_BIT);
glViewport(0,0,1920,1080);
glOrtho(0,1920,0,1080,0,1);
glColor3f(1.0,0.0,0.0);
float tmp = float(qrand()%1000);
float count = (float)counts * 10.0f;
glLineWidth(3.0f);
glBegin(GL_LINE_LOOP);
glVertex2f(count ,count );
glVertex2f(count + 100,count);
glVertex2f(count + 50,count + 100);
glEnd();
qDebug()<<QString("current tmp is %1").arg(count);
}
void QTestOffScreen::initialize()
{
if (!fbo)
{
fbo = new QGLFramebufferObject(1920,1080,GL_TEXTURE_2D);
}
fbo->bind();
}
void QTestOffScreen::renderNow()
{
bool needsInitialize = false;
if (!m_context)
{
m_context = new QOpenGLContext(this);
m_context->setFormat(requestedFormat());
m_context->create();
if (m_context->isValid())
{
qDebug()<<"Right Here when creating m_context in renderNow";
}
needsInitialize = true;
}
if ( !m_context->makeCurrent(this) )
{
qDebug()<<"This fails in makeCurrent";
}
if (needsInitialize)
{
initializeOpenGLFunctions();
initialize();
}
render();
qDebug()<<counts;
counts--;
fbo->toImage().save(QString::number(counts) + QString(".png"));
m_context->doneCurrent();
if (counts >= 0)
{
m_update_pending = false;
emit doneImg(counts);
}
}
void QTestOffScreen::setAnimating(bool animating)
{
m_animating = animating;
m_update_pending = false;
if (m_animating)
renderLater();
}
bool QTestOffScreen::event(QEvent *event)
{
switch (event->type())
{
case QEvent::UpdateRequest:
m_update_pending = true;
renderNow();
return true;
default:
return QOffscreenSurface::event(event);
}
}
void QTestOffScreen::renderLater()
{
if (!m_update_pending)
{
m_update_pending = true;
QCoreApplication::postEvent(this,new QEvent(QEvent::UpdateRequest));
}
}
void QTestOffScreen::generateImg(QImage *tmp_img_pointer)
{
GLint viewPort[4]={0};
glGetIntegerv(GL_VIEWPORT,viewPort);
int win_width,win_height;
win_width = 1920;
win_height = 1080;
GLubyte *colorArr=new GLubyte[win_width*win_height*3];
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glReadBuffer (GL_FRONT);
int tmp_x,tmp_y;
tmp_x = 0;
tmp_y = 0;
glReadPixels(tmp_x,tmp_y,win_width,win_height,
GL_RGB,GL_UNSIGNED_BYTE,colorArr);
int winrows = tmp_img_pointer->height();
int wincols = tmp_img_pointer->width ();
for(int ii=0; ii < winrows * wincols * 3; ii ++)
{
if((colorArr[ii] <0)|(colorArr[ii] >255))
{ colorArr[ii] = 255; }
}
for(int j=0;j<winrows;j++)
for(int i=0;i<wincols;i++)
{
int index=(j*wincols+i)*3;
QRgb value=qRgb(colorArr[index+2],
colorArr[index+1],
colorArr[index ]);
tmp_img_pointer->setPixel(i,winrows-j-1,value);
}
delete colorArr;
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "qtestoffscreen.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
QTestOffScreen *scr;
private slots:
void ReceiveCurrentIndex(int);
};
#endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSurfaceFormat format;
format.setSamples(1);
format.setRenderableType(QSurfaceFormat::OpenGL);
scr = new QTestOffScreen();
connect(scr,SIGNAL(doneImg(int)),this,SLOT(ReceiveCurrentIndex(int)));
scr->setFormat(format);
scr->setAnimating(true);//Start rendering animation here.
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::ReceiveCurrentIndex(int)
{
Sleep(100);
scr->renderLater();
}
I have a dialog that is minimized in its parent window. When I call frameGeometry() the result is active dialog's(not minimized) numbers.
I want to know where the titleBar is. (when dialog minimized just shown titleBar of the dialog)
Can you try this
header file
#ifndef MYDIALOG_H
#define MYDIALOG_H
#include <QtWidgets/QDialog>
#include <QtWidgets/qmainwindow.h>
class MyDialog : public QDialog
{
Q_OBJECT
public:
MyDialog(QWidget *parent = 0);
~MyDialog();
protected:
virtual bool nativeEvent(const QByteArray & eventType, void * message, long * result);
};
class MyWindow : public QMainWindow
{
Q_OBJECT
public:
MyWindow();
~MyWindow();
private:
MyDialog * m_dialog;
};
#endif // MYDIALOG_H
source file
#include "mydialog.h"
#include <windows.h>
#include <windowsx.h>
#include <QDebug>
#include <QTimer>
MyDialog::MyDialog(QWidget *parent)
: QDialog(parent)
{
setStyleSheet("QDialog{background-color: red}");
}
MyDialog::~MyDialog()
{
}
bool MyDialog::nativeEvent(const QByteArray & eventType, void * message, long * result)
{
MSG* msg = (MSG*)(message);
if (msg->message == WM_NCLBUTTONDOWN)
{
if (isMinimized())
{
QTimer::singleShot(50, this, SLOT(showNormal()));
*result = 0;
return true;
}
else
{
int mouseX = GET_X_LPARAM(msg->lParam);
int mouseY = GET_Y_LPARAM(msg->lParam);
QRect frame = frameGeometry();
QRect content = geometry();
qDebug() << "frame: " << frame;
qDebug() << "content: " << content;
if (mouseY < content.y() && mouseY >= frame.y())
{
qDebug() << "Hit title bar";
showMinimized();
}
}
}
*result = 0;
return false;
}
MyWindow::MyWindow()
:QMainWindow()
{
setStyleSheet("QMainWindow{background-color: blue}");
showMaximized();
m_dialog = new MyDialog(this);
m_dialog->showMinimized();
}
MyWindow::~MyWindow()
{
}
I am trying to create a project in which I have a progressbarV class which creates a QProgressBar. I am calling this class in my mainWindow. My aim is to navigate to another screen when I click on the progressbar. I tried to implement KeyRleaseEvent for this purpose, but no matter what I do, I keep getting the error "QObject::connect: No such signal progressbarV::keyReleaseEvent()". I would much appreciate any help I could get to resolve this issue.
Please find my code below:-
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QWidget>
#include <QProgressBar>
#include <QLabel>
#include <QPixmap>
#include <QPushButton>
#include <QtWidgets>
#include <QProcess>
#include "headerfiles/progressbarV.h"
#include "headerfiles/redzonesettingsscreen.h"
class progressbarH;
class redZoneSettingsScreen;
class MainWindow : public QMainWindow//,public QProcess
{
Q_OBJECT
private:
progressbarV *progressbar_V_left;
public:
MainWindow();
~MainWindow();
void GetObjects(redZoneSettingsScreen *);
private slots:
void handleSettingsButtonPressed();
/*protected:
virtual void keyReleaseEvent(QKeyEvent *); //Q_DECL_OVERRIDE;*/
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "headerfiles/mainwindow.h"
redZoneSettingsScreen *gotoSettingsScreen;
MainWindow::MainWindow()
{
progressbar_V_left = new progressbarV;
progressbar_V_left->setParent(this);
progressbar_V_left->setGeometry(350,200,90,450);
progressbar_V_left->setTitle("Height");
progressbar_V_left->setData(labelCurHeight->getDataValue());
progressbar_V_left->setMinVal(0);
progressbar_V_left->setMaxVal(labelMaxHeight->getDataValue());
connect(progressbar_V_left, SIGNAL (keyReleaseEvent()), this, SLOT
(handleSettingsButtonPressed()));
}
MainWindow::~MainWindow()
{
delete progressbar_V_left;
}
void MainWindow::GetObjects(redZoneSettingsScreen *button)
{
gotoSettingsScreen = button;
}
void MainWindow::handleSettingsButtonPressed()
{
gotoSettingsScreen->hide();
gotoSettingsScreen->show();
this->hide();
}
/*void MainWindow::keyReleaseEvent(QKeyEvent *event)
{
}*/
progressbarV.h
#ifndef PROGRESSBARV_H
#define PROGRESSBARV_H
#include <QWidget>
#include <QProgressBar>
#include <QLabel>
#include <QPixmap>
class progressbarV: public QWidget
{
Q_OBJECT
private:
QProgressBar *progressbar_V;
QLabel *labelRedDanger, *labelYellowWarning;
float maxScaledHeight, redZoneScaledHeight, yellowZoneScaledHeight;
int spn, spn_value;
QString title;
int data;
short minVal;
short maxVal;
public:
progressbarV();
~progressbarV();
void setSPN(int);
int getSPN();
void setSPN_Value(int);
int getSPN_Value();
void setTitle(QString);
QString getTitle();
void setData(int);
int getData();
void setMinVal(short);
short getMinVal();
void setMaxVal(short);
short getMaxVal();
/*void setLowError(short);
short getLowError();
void setLowWarning(short);
short getLowWarning();
void setHighError(short);
short getHighError();
void setHighWarning(short);
short getHighWarning();*/
QProgressBar* getProgressBarV();
protected:
void keyReleaseEvent(QKeyEvent *); //Q_DECL_OVERRIDE;
};
#endif // PROGRESSBARH_H
progressbarV.cpp
#include "headerfiles/progressbarV.h"
progressbarV::progressbarV()
{
progressbar_V = new QProgressBar;
progressbar_V->setParent(this);
progressbar_V->setStyleSheet("QProgressBar{ border: solid grey; border-
width: 6; border-radius: 12; text-align: center;},
QProgressBar::chunk{background-color: limegreen; width: 0px; margin:
0px;}");
progressbar_V->setGeometry(2,0,50,200);
progressbar_V->setOrientation(Qt::Vertical);
maxScaledHeight = (200*100)/120;
redZoneScaledHeight = 200 - ((maxScaledHeight*105)/100);
yellowZoneScaledHeight = 200 - ((maxScaledHeight*90)/100);
QPixmap mypixRed(":/images/images/redZone.png");
labelRedDanger = new QLabel;
labelRedDanger->setParent(this);
labelRedDanger->setGeometry(8,redZoneScaledHeight,38,3);
labelRedDanger->setPixmap(mypixRed);
QPixmap mypixYellow(":/images/images/yellowZone.png");
labelYellowWarning = new QLabel;
labelYellowWarning->setParent(this);
labelYellowWarning->setGeometry(8,yellowZoneScaledHeight,38,3);
labelYellowWarning->setPixmap(mypixYellow);
}
progressbarV::~progressbarV()
{
delete progressbar_V;
delete labelRedDanger;
delete labelYellowWarning;
}
void progressbarV::setSPN(int val)
{
spn = val;
}
int progressbarV::getSPN()
{
return spn;
}
void progressbarV::setSPN_Value(int val)
{
spn_value = val;
}
int progressbarV::getSPN_Value()
{
return spn_value;
}
void progressbarV::setTitle(QString mTitle)
{
title = mTitle;
}
QString progressbarV::getTitle()
{
return title;
}
void progressbarV::setData(int mData)
{
data = mData;
progressbar_V->setValue(data);
}
int progressbarV::getData()
{
return data;
}
void progressbarV::setMinVal(short mMinVal)
{
minVal = mMinVal;
progressbar_V->setMinimum(minVal);
}
short progressbarV::getMinVal()
{
return minVal;
}
void progressbarV::setMaxVal(short mMaxVal)
{
maxVal = mMaxVal;
progressbar_V->setMaximum(maxVal);
}
short progressbarV::getMaxVal()
{
return maxVal;
}
QProgressBar *progressbarV::getProgressBarV()
{
return progressbar_V;
}
void progressbarV::keyReleaseEvent(QKeyEvent *event)
{
}
Since I am new to QT, kindly give me solutions in the form of code snippets
Thanks in advance,
Sam
you need to declare keyReleaseEvent as a public SLOT
public slots:
void keyReleaseEvent(QKeyEvent *); //Q_DECL_OVERRIDE;
so that QT can connect to it using the old connection style.
I'm Qt beginner and have a problem:
I'm using QT(4.8.4) with C++ using QTCreator(2,72).
When I attempt to compile the program I get:
expected primary-expression before ')' token on Line 26.
My main.cpp: Part/Section of the program
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include "view.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
createActions();
createMenus();
//Fenster für Visualisierung
ui->dockWidget->setWidget(view); //ERROR Line 26
ui->dockWidget->setWindowTitle("Visualisierung");
ui->dockWidget->setGeometry(20,200,300,300);
}
My view.cpp:
#include "view.h"
#include <QtGui>
#include <GL/glu.h>
#include <QtOpenGL/QGLWidget>
extern QVector<QMatrix4x4> T_tracked_Point_Cam;
extern QVector<QMatrix4x4> T_approx_Point_Cam;
// Konstruktor
view::view(QWidget *parent) :
QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
xRot = 0;
yRot = 0;
zRot = 0;
zoom = 0;
virtuellerAbstand = 0;
xT = 0;
yT = 0;
trackPoint = false;
laserPoint = false;
laserOrients = false;
gitterPoint = true;
Cam_Koo_Trans_X = 0;
Cam_Koo_Trans_Y = 0;
Cam_Koo_Trans_Z = 0;
}
// Destruktor
view::~view()
{}
main.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QDebug>
#include <QMessageBox>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void openDCMFile();
void drawDICOMImg(std::string fileDICOM);
private:
Ui::MainWindow *ui;
void createActions();
void createMenus();
QMenu *fileMenu;
QAction *openAct;
signals:
void AnzeigeGetracktePunkte(bool);
void AnzeigeLaserPunkte(bool);
void AnzeigeLaserOrients(bool);
void AnzeigeGitterPunkte(bool);
void update_view();
};
#endif // MAINWINDOW_H
vieh.h:
#ifndef VIEW_H
#define VIEW_H
#include <QtOpenGL/QGLWidget>
class view : public QGLWidget
{
Q_OBJECT
public:
view(QWidget *parent = 0);
~view();
QSize minimumSizeHint() const;
QSize sizeHint() const;
double x_max, y_max, z_max;
double x_min, y_min, z_min;
void Zeichnen_getrackte_Punkte();
void Zeichnen_Laserpunkte();
void Zeichnen_Laserorients();
signals:
public slots:
....
protected:
.....
private:
.....
};
#endif // VIEW_H
Thanks for the help in advance.
view is just a name of a type. You probably want to pass an instance of it:
ui->dockWidget->setWidget(view());
// ^^