Cannot open source file "ui_QtGuiApplication.h" in default Qt project - c++

I installed the latest QT version and the QT tool for Visual Studio. When creating a new GUI project in Qt, the default program should create an empty window, but it seems that I'm getting an E1696 error in Visual Studio Community: "cannot open source file "ui_QtGuiApplication4.h".
The error takes place in the default header class created for the project:
#include <QtWidgets/QMainWindow>
#include "ui_QtGuiApplication4.h"
class QtGuiApplication4 : public QMainWindow
{
Q_OBJECT
public:
QtGuiApplication4(QWidget *parent = Q_NULLPTR);
private:
Ui::QtGuiApplication4Class ui;
};
The Ui tag is also not recognized.
I added the additional include directiories for the QT path and I tried switching up between the 64bit and 32bit version of QT, but I'm getting the same error.
Any help would be appreciated!

The ui_<YourClass>.h header file is a file that only gets generated for you when you compile your project. Qt's User Interface Compiler uic will read your .ui file(s) and create the corresponding ui_ headers before the actual C++ compiler is invoked.
So you have to give it at least one compile run to generate the file. Then your IDE should be smart enough to find it.
FYI: Using QtCreator 4.12 you won't even have to compile. The clang backend process will generate the file in a temp folder somewhere probably to give you the proper code inspections (regarding code completion and so on). As I read from your question you're using Visual Studio which doesn't seem to do that.

Related

OpenCASCADE 7.6.0 not compiling with a .NET 6.0 class library with Visual Studio 2022 (Windows 10)

Steps to reproduce:
Install a version of Visual Studio (I used VS Community 2022). Install OpenCASCADE 7.6.0.
Create a C++ .NET CLR project using Visual Studio 2022 targeting .net6.0.
Change settings to include OpenCASCADE header and library files.
Edit the main header by replacing the code within it with below:
#pragma once
//for OCC graphic
#include <OpenGl_GraphicDriver.hxx>
//wrapper of pure C++ classes to ref classes
#include <NCollection_Haft.h>
namespace ClrClsLibDotNetCoreMwe {
public ref class Class1
{
// TODO: Add your methods for this class here.
};
}
Attempt to build.
Issue: The build fails with the following complain:
1>C:\OpenCASCADE-7.6.0-vc14-64\opencascade-7.6.0\inc\NCollection_DefaultHasher.hxx(34,1): error C2872: 'HashCode': ambiguous symbol
1>C:\OpenCASCADE-7.6.0-vc14-64\opencascade-7.6.0\inc\NCollection_DefaultHasher.hxx(34,1): message : could be 'HashCode'
1>C:\OpenCASCADE-7.6.0-vc14-64\opencascade-7.6.0\inc\NCollection_DefaultHasher.hxx(34,1): message : or 'System::HashCode'
What fixes the problem:
Either Targeting .NET Framework instead of .NET Core (/clr instead of /clr:netcore).
Or removing one of the headers.
Please see if there is a way where I can keep both the headers and target .NET Core?
I have looked around for a possible solution before posting this question here. A promising solution was to disable implicit usings. However, that didn't pan out.
I had the same problem.
In my case, the "using namespace System;" included in the header file. The text caused the problem.
Thanks!

VS2019:fatal error C1083 Cannot open header file: 'opencv.hpp'

It is all fine when I was writing the code, that is, when I included the header file "opencv2/opencv.hpp",and VS2019 can indeed "see" it,in other words, I can use the class that is in the opencv.hpp, but only when I complied the project,c1083 occurred
before i added the function DrawLine(),i compiled for times,with no err.and then i added the function DrawLine(..),error occurred
this is the total source code
a.ha.cpp
//a.h
#include<opencv2\opencv.hpp>
using namespace cv;
class Canvas{
Mat mat_canvas;
void Init(){
mat_canvas.create(1024,1024,CV_32FC3);
}
void DrawLine(float ax,float ay,float bx,float by);
}
//a.cpp
#include"a.h"
void Canvas::DrawLine(float ax,float ay,float bx,float by){
cv::line(this->mat_canvas,Point2f(ax,ax),Point2f(bx,by),Scalar(1,1,1));
}
error msg was:
fatal error C1083 Cannot open header file: 'opencv.hpp': no such file or dir
i know i can create a new solution and move my old solution to it,but it takes time,and i can't actually know whether this issue will happen again in my new solution
Any answer will be helpful
Actually there are most of the time possibility of missing "Additional include directory path" or wrongly setup.
Where to find in Visual Studio:
To set this compiler option in the Visual Studio development environment
Open the project's Property Pages dialog box. For details, see Set
C++ compiler and build properties in Visual Studio.
Select the Configuration Properties > C/C++ > General property page.
Modify the Additional Include Directories property.
Visual Studio 2019 C++ Project configuration
Example project setup is described in below link:
Example setup

Visual C++ : XGBoost does not work when called from a DLL

I have a requirement to use XGBoost within a Visual C++ project DLL.
I have been able to download and build the XGBoost source using VC++ and CMake.
When I include the XGBoost code in a test console application, it works fine.
However, when I try to replicate what I've done with the console application in a DLL project, it won't compile.
I am struggling to even use a basic XGBoost type within the project.
I suspect the problem is my ignorance with DLL projects and would appreciate your help.
Here's what's happening in my DLL project:
When I use the following include as the very first line in a cpp class file, it compiles:
#include <xgboost\c_api.h>
With it compiling, if I try to use a simple type defined in this include file, the build fails with the following message:
...\dll_test\xgb_driver.cpp(20): error C2065: 'BoosterHandle': undeclared identifier
This is the line that causes the error:
BoosterHandle my_handle;
"BoosterHandle" is in fact defined in <xgboost\c_api.h>
When I put the include below any other include, I get the following error messages:
1>c:\tools\src\xgboost\include\xgboost\c_api.h(29): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\tools\src\xgboost\include\xgboost\c_api.h(29): error C2146: syntax error: missing ';' before identifier 'bst_ulong'
Below is a little more information on what I did to get XGBoost working with a console app and how I created the DLL project.
=-=-=-=-=-=
Here's what I did to use XGBoost with a console. Everything about it seems to work. I've tested the model predictions, and they are
consistent with what I'm seeing in R.
Using the documentation found here:
https://xgboost.readthedocs.io/en/latest/build.html
I downloaded the XGBoost source and built it using CMake and Visual Studio 2015.
Under Project > Linker > Input > Additional Dependencies,
I added the xgboost.lib file
Under Project > Linker > General > Additional Library Directories
I added a reference to ...\xgboost\build\Release
Under Project > VC++ Directories > Include Directories
I added the path to ...\xgboost\rabit\include and ...\xgboost\include
I put the xgboost.dll in the directory where the .exe is generated.
From here, it was smooth sailing.
=-=-=-=-=-=
Here's what I've done to create a Visual C++ DLL Project:
After choosing File > New > Project, I select an ATL DLL Project (this is part of the project requirement).
For the XGBoost include to the project, I repeated steps 1-5 above, but placed the xgboost.dll file where the
project DLL would be generated.
Here is the source for the header file for the simple class I have created:
#pragma once
class XGB_Driver
{
public:
XGB_Driver();
~XGB_Driver();
float callXGB(float sample_input);
};
Here is the source for the simple cpp file:
#include <xgboost/c_api.h>
#include "stdafx.h"
#include "XGB_Driver.h"
XGB_Driver::XGB_Driver()
{
}
XGB_Driver::~XGB_Driver()
{
}
float XGB_Driver::callXGB(float simple_input) {
BoosterHandle my_handle;
return(0);
}
Why this doesn't work for the ATL DLL project, but does for the console app really has me banging my head against the keyboard.
Your help would be very much appreciated.
Best,
Dave
With the help of CristiFati, I believe this question has been answered.
For whatever reason, it seems that using XGBoost with C++ in a DLL project requires additional includes above and beyond what is required for using it in a console application.
I am currently building the DLL project with the addition of:
#include <cstdint>

qtreeviewprivate.h : no such file

I have a problem with Qt 5.5 and QTreeView. qtreeview.h (Yes, it's from Qt folder) has compiler error:
fatal error: QTreeViewPrivate: No such file or directory.
My Qt5.5 library doesn't know about QTreeViewPrivate, but qtreeview.h needs it. Every simple code like this QTreeWidget *fileList = new QTreeWidget(); or else linked to QTreeView makes my complier angry! Maybe it's some bug? Where is QTreeViewPrivate ?
Check if you added the correct library to your project file:
QT += widgets
See documentation: http://doc.qt.io/qt-5/qtreeview.html
Check if you added the correct Qt folder path to your project.
In project properties, c/c++ general libraries.
Well, I found the solution. To use QTableWidget that no need QTableViewPrivate's header I edit qtableview.h in my Qt folder, I replased #include <QTreeViewPrivate> to class QTreeViewPrivate;. Now code works fine!

Qt Signals and Slots break when converting Visual C++ project to boost build makefile project

I created a Visual C++ Project using MSVS and I just made another project in MSVS so that the same code can be built using boost build. I can currently build my project using a Visual C++ project as well as a Makefile project that uses boost build.
There is a difference between the two builds though concerning QT Signals and Slots.For the following code,when I call MyThread::Start() the onTimeout() slot is called when the project is built in visual studio, but not called when built using boost build.
class MyThread: public QObject{
Q_OBJECT
public:
bool start();
public Q_SLOTS:
void onTimeout();
private:
QThread m_thread;
QTimer m_timer;
};
void MyThread::start()
{
m_timer.start(1000);
m_thread.setObjectName(QString("GigeControl"));
m_thread.start();
m_timer.moveToThread(&m_thread);
}
void MyThread::onTimeout()
{
//Do Stuff
}
I am really having a hard time trying to figure out the differences between the two
builds,especially since I need those signals and slots to work.
One major difference that I have noticed so far is that the Visual C++ project is built using /Zp1 so all structures are 1 byte alligned. This is not done in the boost project as I don't know how to. I've seen people on the internet mentioning that structure allignments (especially using #pragma pack can cause problems with QT).
If anyone has some experience they might be able to share it would be greatly appreciated.
It looks like the problem was in fact the structure packing. I am writing code for a couple of code bases that are being merged and there coincidentally happens to be some packing conflicts.
To fix the packing for building with boost-build all I had to to was add this to the lib being generated in the Jamfile:
lib foo
:
...
:
...
<target-os>linux:<cxxflags>-fpack-struct=1
<target-os>windows:<cxxflags>-Zp1
;
This worked for me so hopefully it will help someone else out if they get stuck here too