这是我的标题:
#ifndef BARELYSOCKET_H
#define BARELYSOCKET_H
#include <QObject>
//! The First Draw of the BarelySocket!
class BarelySocket: public QObject
{
Q_OBJECT
public:
BarelySocket();
public slots:
void sendMessage(Message aMessage);
signals:
void reciveMessage(Message aMessage);
private:
// QVector<Message> reciveMessages;
};
#endif // BARELYSOCKET_H
Run Code Online (Sandbox Code Playgroud)
这是我的班级:
#include <QTGui>
#include <QObject>
#include "type.h"
#include "client.h"
#include "server.h"
#include "barelysocket.h"
BarelySocket::BarelySocket()
{
//this->reciveMessages.clear();
qDebug("BarelySocket::BarelySocket()");
}
void BarelySocket::sendMessage(Message aMessage)
{
}
void BarelySocket::reciveMessage(Message aMessage)
{
}
Run Code Online (Sandbox Code Playgroud)
我收到链接器错误:
undefined reference to 'vtable for BarelySocket'
Run Code Online (Sandbox Code Playgroud)
Message是一个复杂的struct …我知道这个问题已被问过很多次,但我在这里找不到解决方案,也没有在谷歌找到解决方案.
这是我的头文件
#ifndef MAINCONTROLLER_H
#define MAINCONTROLLER_H
#include <QSettings>
#include <QDebug>
#include <QDir>
#include <QObject>
#include "PhTools/PhString.h"
#include "PhStrip/PhStripDoc.h"
class MainController : public QObject
{
Q_OBJECT
public:
explicit MainController(QObject *parent = 0);
void loadSettings();
PhString getLastFile();
void setLastFile(PhString fileName);
bool openDoc(PhString fileName);
signals:
void docChanged();
private:
QSettings * _settings;
PhStripDoc * _doc;
};
#endif // MAINCONTROLLER_H
Run Code Online (Sandbox Code Playgroud)
我的CPP档案:
#include "MainController.h"
MainController::MainController(QObject *parent) :
QObject(parent)
{
_doc = new PhStripDoc();
loadSettings();
}
void MainController::loadSettings()
{
_settings = new QSettings(QDir::homePath() + "/Library/Preferences/com.me.me.plist", QSettings::NativeFormat);
getLastFile(); …Run Code Online (Sandbox Code Playgroud) 为什么插槽Reset()不起作用?我希望按钮"reset"将sider的值重置为零.
class MySlider : public QSlider
{
public:
MySlider(Qt::Orientation orientation, QWidget *parent = 0) : QSlider(orientation parent){}
public slots:
void Reset()
{
this->setValue(0);
}
};
//it doesnt work when i try this
MySlider * Slider = new MySlider(Qt::Horizontal, this);
QPushButton *Reset = new QPushButton(tr("Reset"), this);
connect(Reset, SIGNAL(clicked()), Slider, SLOT(Reset()) );
Run Code Online (Sandbox Code Playgroud) 当我取消对信号槽所需的 Q_OBJECT 宏的注释时,我得到了一个对 vtable 的未定义引用,用于 MyApp 错误,但没有宏它可以完美编译,但没有它我无法使用信号和槽。我想我可能做错了一些愚蠢的事情,但请尝试提供帮助,因为我真的找不到问题所在。哦,我知道我的代码不整洁,正在处理它。
我的应用程序.h:
#ifndef MYAPP_H
#define MYAPP_H
#include <QApplication>
#include <QEvent>
#include <QObject>
#include <QDebug>
class MyApp : public QApplication
{
public:
MyApp( int argc, char** argv );
protected:
bool eventFilter(QObject *object, QEvent *event);
signals:
void focusG();
void focusL();
};
#endif // MYAPP_H
Run Code Online (Sandbox Code Playgroud)
myapp.cpp:
#include "myapp.h"
MyApp::MyApp(int argc, char **argv): QApplication(argc, argv)
{
installEventFilter(this);
}
bool MyApp::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::ApplicationDeactivate)
{
qDebug() << "Focus lost";
//focusL();
}
if (event->type() == …Run Code Online (Sandbox Code Playgroud) 我需要知道我做错了什么.
我试过研究它,但我真的找不到任何与我的情况有关的东西.我是QT的新手,调试信号和插槽对我来说有点技术.
我想做的只是简单:创建一个不断向我的QProgressBar小部件发送信号的线程.
这是我的基本代码片段:
thread.h
class MyThread : public QThread
{
public:
MyThread(QWidget * parent = 0);
signals:
void valueChanged(int value);
protected:
void run();
};
Run Code Online (Sandbox Code Playgroud)
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
MyThread * test = new MyThread(this);
connect(test,SIGNAL(valueChanged(int)),ui->progressBar,SLOT(setValue(int)));
test->start();
}
Run Code Online (Sandbox Code Playgroud)
thread.cpp
MyThread::MyThread(QWidget * parent)
{
}
void MyThread::run(){
emit valueChanged(10); //for simplicity
}
void MyThread::valueChanged(int value){
}
Run Code Online (Sandbox Code Playgroud)
我的progressBarUI上只有一个,我main的默认值相同.
无论如何,在运行代码时.我继续no such signal从我的线程课程中得到这个.我可以知道我做错了什么吗?我还想澄清我的理解是否正确signals and slots用我自己的话来说:它意味着slot每次signal调用时都会触发.