Home > Back-end >  Consult! With QT development under the DLL project of how to use the function of signals and slots m
Consult! With QT development under the DLL project of how to use the function of signals and slots m

Time:10-10

Me directly post code, facilitate everybody correct, first posted on the DLL project code, documents the following
 # # ifndef UNTITLED36_H 
# define UNTITLED36_H

# include "untitled36_global. H"
# include "QTimer
"
The 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 - & gt; Start (1000);
The connect (t, SIGNAL (timeout ()), t, SLOT (test ()));
}

Void Untitled36: : test ()
{
QDebug () & lt; & lt;" Test ";
}

Pro file
 # -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
#
# the Project created by QtCreator T16 2017-04-14: not
#
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

QT GUI -=
QT +=network widgets

TARGET=untitled36
The TEMPLATE=lib

DEFINES +=UNTITLED36_LIBRARY

# The following define top service your compiler emit warnings if you use The
# any feature of Qt which as had been marked as deprecated (the exact warnings
# depend on your compiler). Both 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 the if You use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select the to disable deprecated APIs only up to a certain version of Qt.
# # DEFINES +=QT_DISABLE_DEPRECATED_BEFORE=0 x060000 disables all the APIs deprecated before Qt 6.0.0

SOURCES +=untitled36. CPP

HEADERS +=untitled36. H \
Untitled36_global. H

Unix {
Target. The path=/usr/lib
INSTALLS +=target
}

 # # ifndef UNTITLED36_GLOBAL_H 
# define UNTITLED36_GLOBAL_H

#include

# if defined (UNTITLED36_LIBRARY)
# define UNTITLED36SHARED_EXPORT Q_DECL_EXPORT
# the else
# define UNTITLED36SHARED_EXPORT Q_DECL_IMPORT
# endif

# endif//UNTITLED36_GLOBAL_H

Next is to call a small demo
 # include "mainwindow. H" 
#include

Int main (int arg c, char * argv [])
{
QApplication a (arg c, argv);
The MainWindow w;
Baron how ();

Return a.e xec ();
}

 # # ifndef MAINWINDOW_H 
# define MAINWINDOW_H

#include
# include "untitled36. H"

The namespace Ui {
The class MainWindow.
}

The 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)
{
The UI - & gt; SetupUi (this);
Untitled36 * U;
U - & gt; init();
}

MainWindow: : ~ MainWindow ()
{
Delete the UI;
}

 # -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
#
# the Project created by QtCreator T10:2017-03-23 fortified
#
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

QT +=core GUI network

GreaterThan (QT_MAJOR_VERSION, 4) : QT +=widgets XML

TARGET=LoadDll
The TEMPLATE=app

# The following define top service your compiler emit warnings if you use The
# any feature of Qt which as had been marked as deprecated (the exact warnings
# depend on your compiler). Both 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 the if You use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select the to disable deprecated APIs only up to a certain version of Qt.
# # DEFINES +=QT_DISABLE_DEPRECATED_BEFORE=0 x060000 disables all the APIs deprecated before Qt 6.0.0


+=the main SOURCES. The 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/

It's all here, the problem is run, direct stopped running, debugging time errors as follows

CodePudding user response:

Can see is a pointer, but the specific how to produce, I don't know much about the principle and requests

CodePudding user response:

Untitled36 * U; To Untitled36 * U=new Untitled36 (this);
  • Related