我的用户界面遇到了一些问题。我试图让它可以移动,但我不断得到随机错误。以下是错误的屏幕截图:http://prntscr.com/79esqu
DraggableWindow.cpp代码:
#include "DraggableWindow.h"
#include <QWidget>
#include <QMainWindow>
#include <QPoint>
#include <QMouseEvent>
#include <Qt>
DraggableWindow::DraggableWindow(QWidget *parent)
: QMainWindow(parent)
, m_captured(false)
, m_last_event_pos(QPoint(0, 0))
{
}
void DraggableWindow::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
m_last_event_pos = event->pos();
m_captured = true;
}
}
void DraggableWindow::mouseMoveEvent(QMouseEvent *event)
{
if(m_captured)
{
this->move(this->pos() + (event->pos()-m_last_event_pos));
}
}
void DraggableWindow::mouseReleaseEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
m_captured = false;
}
}
DraggableWindow.h代码:
#pragma once
#include <QMainWindow>
#include <QWidget>
#include <QMouseEvent>
#include <QPoint>
class DraggableWindow : public QMainWindow
{
Q_OBJECT
public:
explicit DraggableWindow(QWidget *parent = 0);
protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
private:
bool m_captured;
QPoint m_last_event_pos;
};
mainlauncher.cpp的启动脚本:
MainLauncher::MainLauncher(QWidget *parent)
: DraggableWindow(parent)
, ui(Ui::MainLauncher)
{
ui->setupUi(this);
}
我遇到了问题。请帮忙!
答案 0 :(得分:1)
你得到的是链接器错误。好像您的DraggableWindow.cpp
尚未编译。
确保您已将。{1}}包含在.pro文件的DraggableWindow.cpp
部分中,SOURCES
部分包含在DraggableWindow.h
部分。
如果在.pro文件中正确添加它们,则在添加qmake后可能没有运行。尝试HEADERS
,然后Build->Run Qmake