So I've been developing a small ACARS (plane tracking system) for the VATSIM network and apart of this entails using the FSUIPC library to interact with Flight Sim X. I have the program working beautifully in VS2010 but when I attempt to use any functions from FSUIPC I get the error:
"mainwindow.obj:-1: error: LNK2019: unresolved external symbol FSUIPC_Open referenced in **function "public: void __cdecl MainWindow::connectFSUIPC(void)" (?connectFSUIPC#MainWindow##QEAAXXZ)"**
From some research I've learnt that this is a library load error and for the life of me I can't figure out how to get it working. Below is the code for all files I am using.
AcarsTest.pro
#-------------------------------------------------
#
# Project created by QtCreator 2013-12-16T23:56:06
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = AcarsTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += "D:/Windows/QT/Tools/QtCreator/bin/AcarsTest/"
LIBS += -LD:/Windows/QT/Tools/QtCreator/bin/AcarsTest/ -lFSUIPC_User
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <Windows.h>
#include <FSUIPC_User.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void connectFSUIPC();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
main.cpp
#include <Windows.h>
#include "mainwindow.h"
#include <QApplication>
#include "FSUIPC_User.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::connectFSUIPC()
{
DWORD dwResult;
if(FSUIPC_Open(SIM_ANY, &dwResult))
{
}
}
try change code like this
your code:
LIBS += -LD:/Windows/QT/Tools/QtCreator/bin/AcarsTest/ -lFSUIPC_User
replace by
win32:LIBS += "D:/Windows/QT/Tools/QtCreator/bin/AcarsTest/FSUIPC_User.lib"
Related
On windows 7 pro x64 with Qt 5.6.1 this line alone is bringing my CPU up to 10-15%:
QWebEnginePage *page = new QWebEnginePage(this);
Deleting the page later (even immediately) does not help in reducing the usage back to 0-1% as usual for my apps. Any ideas what to do?
Full code causing the problem:
problem.pro
QT += core gui webenginewidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = problem
TEMPLATE = app
SOURCES += main.cpp\
MainWindow.cpp
HEADERS += MainWindow.h
FORMS += MainWindow.ui
problem.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QWebEnginePage>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
problem.cpp
#include "MainWindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Comment the next line to reduce CPU usage back to normal
QWebEnginePage *page = new QWebEnginePage(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
With QNetworkAccessManager I was able to achieve the same result as with the QWebEnginePage, but without the unnecesarry raised CPU usage.
I've created my own class in QT 5.4 with header and source file, then I've implemented there a video player. The problem is, that it's working fine when I'm placing it in the center of the main window or when I'm showing it in a separate window, but when I'm trying to create a Widget container in the main window and promote widget to it, it gives me some errors:
'videowindow' does not name a type
'widget' was not declared in this scope
expected type-specifier before 'videowindow'
So, here is the code:
videowindow.h - header of my implemented class
#ifndef VIDEOWINDOW_H
#define VIDEOWINDOW_H
#include "mainwindow.h"
class videoWindow
{
private:
QMediaPlayer *player;
QMediaPlaylist *playlist;
public:
videoWindow();
void video_enable();
void widget();
};
#endif // VIDEOWINDOW_H
videowindow.cpp - source
#include "videowindow.h"
#include "mainwindow.h"
videoWindow::videoWindow()
{
}
void videoWindow::video_enable()
{
player = new QMediaPlayer;
playlist = new QMediaPlaylist;
playlist->addMedia(QUrl::fromLocalFile("D:\\фото\\video\\P1150277.MOV"));
QVideoWidget *videoWid = new QVideoWidget;
player->setVideoOutput(videoWid);
videoWid->show();
player->setPlaylist(playlist);
playlist->setCurrentIndex(1); // start from a first video in the playlist
player->play();
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtMultimedia>
#include <QtMultimediaWidgets>
#include <QtDebug>
#include <string>
#include <QGraphicsVideoItem>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "videowindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
main.cpp
#include "mainwindow.h"
#include "videowindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
InstantPlayer.pro - .pro file of the project
#-------------------------------------------------
#
# Project created by QtCreator 2016-06-24T11:37:26
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = InstantPlayers
TEMPLATE = app
#
QT += multimedia
QT += multimediawidgets
#
SOURCES += main.cpp\
mainwindow.cpp \
videowindow.cpp \
playerbase.cpp
HEADERS += mainwindow.h \
videowindow.h \
playerbase.h
FORMS += mainwindow.ui \
playerbase.ui
I am having some issues with starting a timer-based object from a dll with the event loop. Therefore I made a minimal example and this is my output:
QObject: Cannot create children for a parent that is in a different thread.
(Parent is MainWindow(0x28fe08), parent's thread is QThread(0x1222aab0), current thread is QThread(0x121421c8)
QObject::startTimer: Timers can only be used with threads started with QThread
MainWindow thread: 0x1222aab0
DllThreadTest thread: 0x121421c8
I am using Windows 8 and Qt5.3.2.
So my questions are:
Why is the object that I create from the dll inside a different thread than the MainWindow? As you can see in the code, I am not using threads.
I can not pass this as a parameter when creating the object from my library as you can see in the first error message. See my example below.
I guess that when I solve the thread-issue, I also solve the timer-problem.
Example:
dllthreadtest.h
#ifndef DLLTHREADTEST_H
#define DLLTHREADTEST_H
#include <QObject>
#include <QTimer>
#if defined TEST_BUILD_DLLTHREADTEST
#define TEST_COMMON_DLLSPEC Q_DECL_EXPORT
#else
#define TEST_COMMON_DLLSPEC Q_DECL_IMPORT
#endif
class TEST_COMMON_DLLSPEC DllThreadTest : public QObject
{
Q_OBJECT
public:
explicit DllThreadTest(QObject *parent = 0);
signals:
public slots:
void onTimeOut();
private:
QTimer timer;
};
#endif // DLLTHREADTEST_H
dllthreadtest.cpp
#include "dllthreadtest.h"
#include <QDebug>
DllThreadTest::DllThreadTest(QObject *parent) :
QObject(parent)
{
timer.start(1000);
}
void DllThreadTest::onTimeOut()
{
qDebug()<<"time out";
}
DllThreadTest.pro
QT += core
QT -= gui
TARGET = DllThreadTest
CONFIG += console
CONFIG -= app_bundle
CONFIG += debug_and_release build_all
CONFIG(debug, debug|release) {
win32: TARGET = $$join(TARGET,,,d)
}
TEMPLATE = lib
DEFINES += TEST_BUILD_DLLTHREADTEST
SOURCES += main.cpp \
dllthreadtest.cpp
HEADERS += \
dllthreadtest.h
I am building it and then including the library in a newly created default project that just creates a QMainWindow. There I instantiate a DllThreadTest-object.
DllImportTest.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = DllImportTest
TEMPLATE = app
INCLUDEPATH += \
$$PWD/libs/
win32{
LIBS += -L$$PWD/libs/ -ldllthreadtest
}
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
maindwindow.cpp (only class of DllImportTest.pro)
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dllthreadtest.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->pushButton,SIGNAL(clicked()),
this,SLOT(onButtonClick()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::onButtonClick()
{
dllThreadTest_=new DllThreadTest;
qDebug()<<"MainWindow thread:"<<this->thread();
qDebug()<<"DllThreadTest thread:"<<dllThreadTest_->thread();
}
main.cpp (entry point of DllImportTest)
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
I'm new to Qt and am trying to figure out how to add a custom widget I've created to my main window.
The widget is pretty simple - I just used Qt Designer to create the default widget (I'm calling it Editor) and then added a button to it. Next I included the header of my custom widget in mainwindow.h and added a pointer to it in my MainWindow class. So far, so good. But when I try to create a new instance of Editor, I get the error:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl Editor::Editor(class QWidget *)" (??0Editor##QEAA#PEAVQWidget###Z) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow##QEAA#PEAVQWidget###Z)
What do I need to do to be able to link my code?
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "editor.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
Editor *editor;
};
#endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
editor = new Editor(0);
}
MainWindow::~MainWindow()
{
delete ui;
delete editor;
}
editor.h:
#ifndef EDITOR_H
#define EDITOR_H
#include <QWidget>
namespace Ui {
class Editor;
}
class Editor : public QWidget
{
Q_OBJECT
public:
explicit Editor(QWidget *parent = 0);
~Editor();
private:
Ui::Editor *ui;
};
#endif // EDITOR_H
editor.cpp:
#include "editor.h"
#include "ui_editor.h"
Editor::Editor(QWidget *parent) :
QWidget(parent),
ui(new Ui::Editor)
{
ui->setupUi(this);
}
Editor::~Editor()
{
delete ui;
}
CustomWidgetTest.pro:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = CustomWidgetTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
editor.cpp
HEADERS += mainwindow.h \
editor.h
FORMS += mainwindow.ui \
editor.ui
Just trying to make a simple web viewer app so I can view a webpage in a widget and I am getting the error:
QWidget: Must construct a QApplication before a QPaintDevice
I feel like this is a problem with the webkit? I am statically linking this project.
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui>
#include <QWebPage>
#include <QtWebKit>
#include "Windows.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QWebView *view = new QWebView(parent);
view->load(QUrl("http://google.com/"));
view->show();
}
MainWindow::~MainWindow()
{
delete ui;
}
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
.pro file
QT += core gui webkit network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = webkittest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
header file
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QWebView>
#include <QUrl>
#include <QtPlugin>
#include <QGridLayout>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QMessageBox>
#include <QDialog>
#include <QtWebKit>
class QAction;
class QCheckBox;
class QComboBox;
class QGroupBox;
class QLabel;
class QLineEdit;
class QMenu;
class QPushButton;
class QSpinBox;
class QTextEdit;
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
protected:
//void closeEvent(QCloseEvent *event);
//void keyPressEvent(QKeyEvent *);
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
signals:
private slots:
//void onSslErrors(QNetworkReply* reply, const QList<QSslError> &errors);
private:
Ui::MainWindow *ui;
QWebView* m_pWebView;
#endif // MAINWINDOW_H
Any ideas what could be causing that?
Fixed this by installing the latest version of Qt framework and dynamically linking webkit as they have disable static linking.