首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Qt QTimeSpan错误LNK2019

Qt QTimeSpan错误LNK2019
EN

Stack Overflow用户
提问于 2013-06-21 20:01:50
回答 1查看 1.2K关注 0票数 0

我使用的是Windows7、QCreator、Qt5.0,我的电脑是x64。

在使用QTimeSpan时,我得到以下错误

代码语言:javascript
复制
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QTimeSpan::~QTimeSpan(void)" (__imp_??1QTimeSpan@@QEAA@XZ) referenced in function "private: void __cdecl MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AEAAXXZ)

mainwindow.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) class QTimeSpan __cdecl operator*(class QTimeSpan const &,int)" (__imp_??D@YA?AVQTimeSpan@@AEBV0@H@Z) referenced in function "class QTimeSpan __cdecl operator*(int,class QTimeSpan const &)" (??D@YA?AVQTimeSpan@@HAEBV0@@Z)

mainwindow.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) class QTimeSpan __cdecl operator-(class QTime const &,class QTime const &)" (__imp_??G@YA?AVQTimeSpan@@AEBVQTime@@0@Z) referenced in function "private: void __cdecl MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AEAAXXZ)


mainwindow.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) class QTime __cdecl operator+(class QTime const &,class QTimeSpan const &)" (__imp_??H@YA?AVQTime@@AEBV0@AEBVQTimeSpan@@@Z) referenced in function "private: void __cdecl MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AEAAXXZ)

debug\Midpoint3_1.exe:-1: error: LNK1120: 4 unresolved externals

我尝试将Qt/libs目录添加到我的计算机的'Environment Variables‘中的路径,但失败了。

以下是源代码: //Midpoint3_1.pro

代码语言:javascript
复制
#-------------------------------------------------
#
# Project created by QtCreator 2013-07-01T03:58:17
#
#-------------------------------------------------

QT       += core gui
QT += widgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Midpoint3_1
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp\


HEADERS  += mainwindow.h \
    ../../../../../../../../Qt/Qt5.0.2/5.0.2/msvc2012_64/include/QTimeSpan/qtimespan.h

FORMS    += \
    mainwindow.ui

//mainwindow.h

代码语言:javascript
复制
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

//MainWindow.cpp

代码语言:javascript
复制
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui>
#include <QtCore>
#include "QTimeSpan/qtimespan.h"
#include <QTime>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->horizontalSlider,SIGNAL(valueChanged(int))
           ,ui->percentage,SLOT(setValue(int)));
}

void MainWindow::on_pushButton_clicked()
{
    QTime vtime1 = ui->time1->time();
    QTime vtime2 = ui->time2->time();
    QTimeSpan vspan = vtime2 - vtime1;
    int vpercentage = ui->percentage->value();
    QTime vtime3 = vtime1 + (vpercentage/100) * vspan;
    //ui->time3->setText(QString );
}


MainWindow::~MainWindow()
{
    delete ui;
}

//main.h

代码语言:javascript
复制
#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

还有一个mainwindow.ui,源代码如下:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>284</width>
    <height>259</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Time Midpoint Calculator</string>
  </property>
  <widget class="QWidget" name="centralWidget">
   <widget class="QWidget" name="layoutWidget">
    <property name="geometry">
     <rect>
      <x>20</x>
      <y>10</y>
      <width>241</width>
      <height>191</height>
     </rect>
    </property>
    <layout class="QVBoxLayout" name="verticalLayout_2">
     <item>
      <layout class="QVBoxLayout" name="verticalLayout">
       <item>
        <layout class="QHBoxLayout" name="horizontalLayout">
         <item>
          <widget class="QLabel" name="label">
           <property name="text">
            <string>Time 1</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QTimeEdit" name="time1"/>
         </item>
        </layout>
       </item>
       <item>
        <layout class="QHBoxLayout" name="horizontalLayout_2">
         <item>
          <widget class="QLabel" name="label_2">
           <property name="text">
            <string>Time 2</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QTimeEdit" name="time2">
           <property name="time">
            <time>
             <hour>12</hour>
             <minute>0</minute>
             <second>0</second>
            </time>
           </property>
          </widget>
         </item>
        </layout>
       </item>
       <item>
        <widget class="QSlider" name="horizontalSlider">
         <property name="minimumSize">
          <size>
           <width>128</width>
           <height>19</height>
          </size>
         </property>
         <property name="maximumSize">
          <size>
           <width>20000</width>
           <height>19</height>
          </size>
         </property>
         <property name="maximum">
          <number>100</number>
         </property>
         <property name="singleStep">
          <number>1</number>
         </property>
         <property name="value">
          <number>50</number>
         </property>
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
         </property>
        </widget>
       </item>
       <item>
        <layout class="QHBoxLayout" name="horizontalLayout_3">
         <item>
          <widget class="QLabel" name="label_3">
           <property name="text">
            <string>Percentage</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QSpinBox" name="percentage">
           <property name="maximumSize">
            <size>
             <width>60</width>
             <height>22</height>
            </size>
           </property>
           <property name="value">
            <number>50</number>
           </property>
          </widget>
         </item>
        </layout>
       </item>
      </layout>
     </item>
     <item>
      <widget class="QPushButton" name="pushButton">
       <property name="text">
        <string>Calculate</string>
       </property>
      </widget>
     </item>
     <item>
      <layout class="QHBoxLayout" name="horizontalLayout_4">
       <item>
        <widget class="QLabel" name="label_4">
         <property name="text">
          <string>Output Time</string>
         </property>
        </widget>
       </item>
       <item>
        <widget class="QLabel" name="time3">
         <property name="text">
          <string>6:00:00 AM</string>
         </property>
        </widget>
       </item>
      </layout>
     </item>
    </layout>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menuBar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>284</width>
     <height>21</height>
    </rect>
   </property>
   <widget class="QMenu" name="menuHelp">
    <property name="title">
     <string>Help</string>
    </property>
    <addaction name="actionThe_Algorithm"/>
    <addaction name="actionThe_Algorithm_2"/>
    <addaction name="actionAbout_Midpoint"/>
   </widget>
   <addaction name="menuHelp"/>
  </widget>
  <widget class="QToolBar" name="mainToolBar">
   <attribute name="toolBarArea">
    <enum>TopToolBarArea</enum>
   </attribute>
   <attribute name="toolBarBreak">
    <bool>false</bool>
   </attribute>
  </widget>
  <widget class="QStatusBar" name="statusBar"/>
  <action name="actionThe_Algorithm">
   <property name="text">
    <string>What is 'Fraction'?</string>
   </property>
  </action>
  <action name="actionThe_Algorithm_2">
   <property name="text">
    <string>The Algorithm</string>
   </property>
  </action>
  <action name="actionAbout_Midpoint">
   <property name="text">
    <string>About Midpoint</string>
   </property>
  </action>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <resources/>
 <connections/>
</ui>

有关qtimespan.h的源代码,请参阅here

下面是这个程序的样子:

EN

回答 1

Stack Overflow用户

发布于 2013-06-21 20:41:29

我认为您正在尝试在C++应用程序中包含并链接到"C“库。如果您的QT是一个C库,那么调用约定将是__cdecl,但是C++可能会寻找与__stdcall或其他约定的链接。在这种情况下,如果您确定使用C库来链接您的CPP应用程序,那么将您的C头文件包含在

#ifdef _cplusplus

外部"C“{

#endif

#在这里包含<您的听众>//例如QtGui和QTCore等标头

#ifdef _cplusplus

}

#endif

这将确保您能够使用C库,而不会出现任何来自CPP应用程序的问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17234758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档