【问题标题】:Add network to Qt Project将网络添加到 Qt 项目
【发布时间】:2017-12-31 08:18:36
【问题描述】:

我尝试使用 QtNetwork 库并将所有依赖项添加到 .pro 文件中。但是当我编译我的代码时,Qt Creator 无法构建项目并声称

C1083:包括“QTcpSocket”:没有这样的文件或目录 - telnet.h:4

我认为将网络添加到 .pro 文件就足够了?

networkmonitor.pro

#-------------------------------------------------
#
# Project created by QtCreator 2017-07-24T13:18:19
#
#-------------------------------------------------

QT += core gui network charts

# greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = networkmonitor
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 \
        telnet.cpp

HEADERS += \
        mainwindow.h \
        telnet.h

FORMS += \
        mainwindow.ui

telnet.h

#ifndef TELNET_H
#define TELNET_H

#include <QTcpSocket>
#include <QTcpServer>
#include <QDebug>

class Telnet
{
public:
    Telnet();

    void sendValues(QString _ip, int _port, QString _message);

private:
    QTcpSocket *socket;
};

#endif // TELNET_H

【问题讨论】:

    标签: c++ qt network-programming


    【解决方案1】:

    通常这意味着您只是忘记重新运行 qmake

    【讨论】:

    • 好的,问题解决了。不知道我必须这样做...谢谢
    • 不用担心。 Qt Creator 在检测 .pro 文件的更改方面很糟糕,因此每次更改该文件时都应该重新运行 qmake
    猜你喜欢
    • 2014-02-27
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-17
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多