我直接貼出代碼好了,方便大家指正,先貼出dll工程的代碼,相關檔案如下
#ifndef UNTITLED36_H
#define UNTITLED36_H
#include "untitled36_global.h"
#include "QTimer"
class UNTITLED36SHARED_EXPORT Untitled36 : public QObject
{
Q_OBJECT
public:
Untitled36();
QTimer *t;
void init();
public slots:
void test();
};
#endif // UNTITLED36_H
#include "untitled36.h"
#include "QDebug"
Untitled36::Untitled36()
{
}
void Untitled36::init()
{
t=new QTimer(this);
t->start(1000);
connect(t,SIGNAL(timeout()),t,SLOT(test()));
}
void Untitled36::test()
{
qDebug()<<"test";
}
pro檔案
#-------------------------------------------------
#
# Project created by QtCreator 2017-04-14T16:10:29
#
#-------------------------------------------------
QT -= gui
QT+=network widgets
TARGET = untitled36
TEMPLATE = lib
DEFINES += UNTITLED36_LIBRARY
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += untitled36.cpp
HEADERS += untitled36.h\
untitled36_global.h
unix {
target.path = /usr/lib
INSTALLS += target
}
#ifndef UNTITLED36_GLOBAL_H
#define UNTITLED36_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(UNTITLED36_LIBRARY)
# define UNTITLED36SHARED_EXPORT Q_DECL_EXPORT
#else
# define UNTITLED36SHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // UNTITLED36_GLOBAL_H
接下來是呼叫的一個小demo
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "untitled36.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
Untitled36 *U;
U->init();
}
MainWindow::~MainWindow()
{
delete ui;
}
#-------------------------------------------------
#
# Project created by QtCreator 2017-03-23T10:34:13
#
#-------------------------------------------------
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets xml
TARGET = LoadDll
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
LIBS+=D:/Qt/Documents/build-untitled36-Desktop_Qt_5_8_0_MinGW_32bit-Debug/debug/untitled36.dll
INCLUDEPATH+=D:/Qt/Documents/untitled36/
都在這里了。 出現的問題是運行是,直接就停止運行了,除錯時錯誤如下
uj5u.com熱心網友回復:
能看出來是指標問題,但具體是怎么產生的,我就不太懂原理了,請求告知uj5u.com熱心網友回復:
Untitled36 *U; 改成 Untitled36 *U=new Untitled36(this);轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/166893.html
標籤:C++ 語言
上一篇:【kimol君的無聊小發明】—用python寫圖片下載器
下一篇:邏輯運算 有點小問題,
