0

Windows 7、QCreator、Qt 5.0 を使用しており、PC は x64 です。

QTimeSpanの使用中に次のエラーが発生します。

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 ディレクトリを追加しようとしましたが、失敗しました。

ソースコードは次のとおりです: //Midpoint3_1.pro

#-------------------------------------------------
#
# 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

//メインウィンドウ.h

#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

#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

#include "mainwindow.h"
#include <QApplication>

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

mainwindow.ui もあります。ソース コードは次のとおりです。

<?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 のソース コードについては、こちらを参照してください。

プログラムは次のようになります。

ここに画像の説明を入力

4

1 に答える 1

0

C++ アプリケーションに「C」ライブラリを含めてリンクしようとしていると思います。QT が C ライブラリの場合、呼び出し規則は __cdecl になりますが、C++ は __stdcall またはその他の規則とのリンクを探している可能性があります。このようなシナリオで、C ライブラリを使用して CPP アプリとリンクしていることが確実な場合は、C ヘッダーを次のように含めます。

#ifdef _cplusplus

extern "C" {

#endif

#include < ここに聞き手 > //たとえば QtGui や QTCore などのヘッダーをここに

#ifdef _cplusplus

}

#endif

これにより、CPP アプリケーションから問題なく C ライブラリを使用できるようになります。

于 2013-06-21T12:41:28.640 に答える