Not sure how many people use QuaZip for opening and working with zip files within Qt, but I'm attempting to open a zip file using the code as follows:
#include "quazip/JlCompress.h"
#include <QDebug>
#include <QtWidgets>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ConnectActions();
...
}
bool MainWindow::LoadArchive(const QString &filename)
{
//qDebug() << "STUB: LoadArchive()";
QuaZip archive_handle(filename);
//Attempt to open the file, return false and display error message
if(!archive_handle.open(QuaZip::mdUnzip)) {
qDebug() << "Archive does not exist or is damaged!";
return false;
}
//Perform some sort of operation, such as loading the images out of the archive
//tidy up
archive_handle.close();
return true;
}
It gives me the error:
QIODevice::open: File access not specified
Archive does not exist or is damaged!
***Error in `/home/adrian/Development/build-CinemaStrips-Desktop_Qt_5_3_GCC_64bit-Debug/CinemaStrips': free(): invalid pointer: 0x00007f2c4b709ce0***
The program has unexpectedly finished.
I can't tell if I'm missing a step since the API instructions are very simple and I've followed them verbatim in my code. As you can see, I'm using Qt5; does QuaZip only work with 4? Finally, is there another way to work with zip files in Qt that anyone has experience with?
Thanks!
To answer my own question, it would seem that my issue was one of relative path resolution to my quazip library in my Qt project file. When specifying a library in the .pro using a relative path, one must remember that Qt resolves relative library paths from the location of the binary when it is run. I, on the other hand, was specifying the location of the library from the perspective of the .pro's (and my codebase's) location. Once rectified, my errors were alleviated.
Related
I know that this has been posted many times,but I could not find the solution from previous posts. I followed tutorial on How to setup Qt and openCV on Windows from wiki Qt.
My .pro file and mainwindows.cpp are shown below. I wanted to open image following the example. What is wrong here? Checked the opencv version and it is the same as libs included. The PATH is also correct.
The cpp file
#include "ui_mainwindow.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
cv::Mat image = cv::imread("C://1.jpg", 1);
cv::namedWindow("My Image");
cv::imshow("My Image", image);
}
MainWindow::~MainWindow()
{
delete ui;
}
and
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = opencvtest
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:\opencv\build\include
LIBS += C:\opencv-build\bin\libopencv_core451.dll
LIBS += C:\opencv-build\bin\libopencv_highgui451.dll
LIBS += C:\opencv-build\bin\libopencv_imgcodecs451.dll
LIBS += C:\opencv-build\bin\libopencv_imgproc451.dll
LIBS += C:\opencv-build\bin\libopencv_features2d451.dll
LIBS += C:\opencv-build\bin\libopencv_calib3d451.dll
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
When program crashes like that under Qt Creator, and you have extra libraries, the very likely reason is that the extra libraries are missing from the runtime PATH.
In this case, you need to add C:\opencv-build\bin to the PATH. There are at least 3 ways to go about it.
Edit the system environment, so that the relevant directory is always in the system PATH. You need to restart Qt Creator for this change to take effect. This is not the recommended way, unless you actually want these things in there also for other purposes.
You can edit the Build environment of the project under Qt Creator Project view. There's separate configuration for each build type, so you may need to do this to them all separately, which both good and bad. It is good, because then you can have different directory for different builds (for example debug vs relase, MSVC vs MinGW builds). It's bad because it's extra hassle and makes it easier to have something wrong.
You can add it to the run environment in the Qt Creator Project view. Then it will be the same for all build types.
In this case, 3 is probably the way to go.
Qt Creator annoyingly does not display any information about which DLL is missing, it just says the program crashed. This can be solved by instead string the "Qt command prompt" for the correct toolchain from Windows Start menu (search Qt and you should find it). Then go to the built .exe directory and run the .exe. You should now get an error dialog where Windows tells you which DLL it failed to find. Then you can look where that DLL is and add it to the path and try again, until the program starts. After you know the directories using this method, you can then add them to Qt Creator as explained above.
I'm trying to run a simple template in release mode on Visual Studio with the Qt extension. So far I've always been running projects in debug mode (never had trouble). Recently, I started with a browser application using webengine its widgets, but it's very slow on debug mode, so. I wanted to make sure it's possible to run with higher performance (on release mode), before continuing.
I was surprised, because the application throws 4 error message pop-ups after each other after trying to run it:
The procedure entry point ?endl#QTextStreamFunctions##YAAEAVQTextStream##AEAV2##Z could not be located in the dynamic link library C:\Qt\5.14.1\msvc2017_64\bin\Qt5WebChannel.dll.
The procedure entry point ?argToQString#QQtPrivate...QString...QStringView... could not be located in the dynamic link library C:\Qt\5.14.1\msvc2017_64\bin\Qt5WebChannel.dll.
Two more similar ones for QDebug and QRhiDepthStencilClearValue.
So instead, I tried to compile a simple project (the direct QtWidgetsApplication template) and it gave me this:
This application failed to start because no Qt Platform plugin could be initialized. Reinstalling the application may fix this problem.
I've been looking for a solution for quite some time now, but I didn't find a clear answer.
My directory: C:\Qt\5.14.1\msvc2017_64
My template code:
#include "QtWidgetsApplication2.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QtWidgetsApplication2 w;
w.show();
return a.exec();
}
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_QtWidgetsApplication2.h"
class QtWidgetsApplication2 : public QMainWindow
{
Q_OBJECT
public:
QtWidgetsApplication2(QWidget *parent = Q_NULLPTR);
private:
Ui::QtWidgetsApplication2Class ui;
};
#include "QtWidgetsApplication2.h"
QtWidgetsApplication2::QtWidgetsApplication2(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
I have no clue of how to fix this problem. Could you please help me out? Thanks in advance!
See if this helps.
Are you trying to start the program by double clicking the .exe ?
I tried to reproduce it:
build a simple project in release mode
run windeployqt ... and delete the generated folder ./platforms
double click on .exe to run it.
and prompts the error message you got.
I am programming with Qt Creator on a Mac (High Sierra 10.13.4). My projects seem to spontaneously break after a few days of work.
The linker error given is: "symbol(s) not found for architecture x86_64".
There is nothing wrong with the code - I open, run, close, and reopen projects and they are suddenly broken. I have also tested this with Qt's provided examples, to the same effect. I can copy-paste the code to a new project and compile it with no problem, but it will eventually do the same thing again.
I have attempted deleting the whole debug output folder of the project to give it a fresh start, but it did not make a difference. Same error.
Has anyone had this issue with QtCreator before? Is there a solution?
I have looked up a lot of very similar questions on here, but they all seem to be errors with the code. Just in case it's the same with me, this is all my code:
//main.cpp
#include "display.h"
#include "frame.h"
#include <QApplication>
int main(int argc, char * argv[])
{
QApplication a(argc, argv);
Display w;
w.show();
return a.exec();
}
Display.h & Frame.h are auto-generated.
//display.cpp
#include "display.h"
#include "ui_display.h"
#include "frame.h"
Display::Display(QWidget *parent) : QMainWindow(parent), ui(new Ui::Display)
{
ui->setupUi(this);
QWidget * f = new Frame(this);
setCentralWidget(f);
}
Display::~Display()
{
delete ui;
}
Frame.cpp last:
#include "frame.h"
#include "ui_frame.h"
Frame::Frame(QWidget *parent) : QFrame(parent), ui(new Ui::Frame)
{
ui->setupUi(this);
}
Frame::~Frame()
{
delete ui;
}
It is not that the linker error is as given. There's way more to it, and you're not including the meat of the message that actually carries meaningful information allowing to debug this issue. Your problem is possibly with the project becoming internally binary-incompatible, and qmake build system not catching onto it. The issue has nothing to do with Qt Creator. The build is done by qmake and make. You'll see those problems if you build from the command line - which I highly advise you to do.
Assuming the sources are in /Users/mycaptain/src/myproject, and that you're using Qt from macports, proceed as follows in terminal:
$ mkdir ~/src/build-myproject
$ cd ~/src/build-myproject
$ /opt/local/libexec/qt5/bin/qmake ../myproject
$ make
#include "DatacommAss1.h"
DatacommAss1::DatacommAss1(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
connect(ui->pushButton, SIGNAL(released()), this, SLOT(handleButton()));
}
void DatacommAss1::handleButton()
{
// change the text
ui->pushButton->setText("Ding Dong");
}
See my code above, I have a button in my ui file called pushButton, but I cannot access it.
I get and error on 'ui' that says "expression must have pointer type".
I'm new to Qt and have no idea how to fix this, any help is appreciated.
Try rebuilding your solution, that should work.
QtCreator sometimes "forget" to rerun qmake. Save all your files (especially .ui) and do Build -> Run QMake (or CMake depending on what you use).
That will regenerate cpp files for your UI. Try rebuilding the project after that.
I'm trying to create a simple GUI application (so far) in Qt with C++ using the MinGW compiler. However, the compiler is informing me that I have a multiple definition of 'WiimoteScouter::WiimoteScouter(QWidget*)' on line 4 of wiimotescouter.cpp. I am using a check to make sure the header isn't included multiple times, but apparently it's not working, and I'm not sure why.
Here's the header file:
#ifndef WIIMOTESCOUTER_H
#define WIIMOTESCOUTER_H
#include <QWidget>
class QLabel;
class QLineEdit;
class QTextEdit;
class WiimoteScouter : public QWidget
{
Q_OBJECT
public:
WiimoteScouter(QWidget *parent = 0);
private:
QLineEdit *eventLine;
};
#endif // WIIMOTESCOUTER_H
And here's the cpp file:
#include <QtGui>
#include "wiimotescouter.h"
WiimoteScouter::WiimoteScouter(QWidget *parent) :
QWidget(parent)
{
QLabel *eventLabel = new QLabel(tr("Event:"));
eventLine = new QLineEdit;
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(eventLabel, 0, 0);
mainLayout->addWidget(eventLine, 0, 1);
setLayout(mainLayout);
setWindowTitle(tr("Wiimote Alliance Scouter"));
}
Lastly, the main.cpp:
#include <QtGui>
#include "wiimotescouter.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
WiimoteScouter wiimoteScouter;
wiimoteScouter.show();
return app.exec();
}
I've seen this happen before when a source file got duplicated in the project (.pro or .pri) file. Check all of the "SOURCES =" and "SOURCES +=" lines in your project file and make sure the cpp file is not in there more than once.
I don't use MinGW but this sounds like a linker error rather than a compiler error. If this is the case then you should check that the .CPP file is not added to the project twice. I also noticed that the extension is "php", this is very unusual as it should be "cpp".
Answer just for reference:
I was including
#include myclass.cpp
instead of
#include myclass.h
This can also happen if you have two .ui files with the same name in different folders. Their corresponding headers are built in the same directory, resulting in one being overwritten. At least that was my problem.
I got this error message when I had my slot declarations listed listed under the signals heading in the header file, rather than the slots one. Another thing for anyone experiencing this error message to check for.
Cut and paste solved the problem and a need to check next time I create Slots manually.
For me it was due to Qt's compilation model in Windows using MinGW.
My code compiled perfectly fine for Linux, but for Windows the linker errors were happening for following files:
Message.cpp
Util.cpp
At first, in the .pro file, I couldn't find any similar file names. Then observing keenly I figured out that, the external google protobuf library, which I was compiling along, had some library files inside its folder named as:
message.cc
util.cc
The cases and the extensions were different, but somehow it created mess in the Qt compilation. I just added an underscore to those library files and the things worked fine.
In my case this was caused by having the function declared globally in a header file.