I had VS 2010 installed already installed in my system.
So when i downloaded QT (I have to use QT as thats what the project req was in) ,i used this link and installed it.
It was able to auto detect the visual C++ compilers and was working fine.
Now I downloaded boost library from boost.org and installed using the following commands from visual studio command prompt:-
> bootstrap.bat msvc
>
> c:\boost_1_54_0>b2 install --prefix=c:/boostinst toolset=msvc-10.0
> variant=debug ,release link=static threading=multi
after that i opened qt creator and added the following code cpp file
#include <boost/regex.hpp>
#include
#include
int main()
{
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
}
and added the library using ADD Library and the following .pro file was generated.
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
INCLUDEPATH += C:\boostinst\include\boost-1_54 #if i remove this line, then also the same error
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../boostinst/lib/ -llibboost_regex-vc100-mt-1_54
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../boostinst/lib/ -llibboost_regex-vc100-mt-1_54d
else:unix: LIBS += -L$$PWD/../../../boostinst/lib/ -llibboost_regex-vc100-mt-1_54
INCLUDEPATH += $$PWD/../../../boostinst/include
DEPENDPATH += $$PWD/../../../boostinst/include
When i try to build , it throws the following error
C:\Users\xxx\newcp\main.cpp:24: error: C1083: Cannot open include file: 'boost/regex.hpp': No such file or directory
Am i Missing something or doing something wrong? Please anyone respond as soon as possible.
SOLVED: Use the following commands for Building boost_154_00 in 32-bit OS Win7 and msvc-10.0
> cd C:\boost_1_54_0\tools\build\v2\engine
> build.bat msvc
>
> cd boost_1_54_0
>
> set PATH=%PATH%;C:\boost_1_54_0\tools\build\v2\engine\bin.ntx86
>
> bjam toolset=msvc-10.0
Then in QT create a new project and paste in main.cpp
#include <QCoreApplication>
#include <boost/regex.hpp>
#include <iostream>
#include <string>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
return a.exec();
}
in .pro add
INCLUDEPATH+=C:\boost_1_54_0
LIBS+=-LC:\boost_1_54_0\stage\lib\
Follow directions here
and then add arguments in qt project->run->arguments
Related
I'm using QT Creator and MinGW (both latest versions) and am having trouble getting the ifstream to use the path argument constructor added in c++17.
Compiling the below code will fail with:
no matching constructor for initialization of 'std::ifstream'
I've got CONFIG += c++17 in my QT .pro file and LIBS += -lstdc++fs
MCV
https://gcc.godbolt.org/z/Lb3MNT
#include <experimental/filesystem>
#include <fstream>
int main() {
const std::experimental::filesystem::path my_path = "C:/";
std::ifstream input_file_stream(my_path);
}
# user1406186, I replicated your same error, and was able to compile it applying the following changes to the .pro file and had to specify the QMAKE I needed to use:
TEMPLATE = app
CONFIG += console c++11
QMAKE_CXXFLAGS += -std=gnu++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
HEADERS +=
LIBS += -lstdc++fs
It also compiled with the following C++14/C++11 standards:
TEMPLATE = app
CONFIG += console c++14
QMAKE_CXXFLAGS += -std=gnu++14
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
HEADERS +=
LIBS += -lstdc++fs
#include<string>
#include<experimental\filesystem>
using namespace std;
using namespace experimental::filesystem;
int main()
{
path soure{current_path()};
soure /="test.txt";
ifstream input{u8path(soure).u8string()};
if(!input)
{
cout<<"source file not exist"<<endl;
}
path dest{current_path()};
dest /="test-copy.txt";
ofstream output{u8path(dest).u8string()};
string line;
while(!getline(input,line).eof())
{
output<<line<<endl;
}
input.close();
output.close();
return 0;
}
Recently build OPENCV 3.4.3 with CMAKE 3.12.4 and MINGW64(32bit) 8.1.0 in Windows 7. Have QT 5.6 and i trying to test this build as QT Console App, but when i compiling with QT only get the message "Press "RETURN" to close this window...".
.PRO file:
CONFIG += c++11
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
OTHER_FILES += test.png
INCLUDEPATH += C:\Users\Test\Desktop\opencv\build\include
LIBS += C:\Users\Test\Desktop\mingw\bin\libopencv_*.dll
main.cpp:
#include <QCoreApplication>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"
using namespace std;
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
cout << "Hello World!" << endl;
cv::Mat mat;
mat = cv::imread("test.png");
cvNamedWindow("hello");
cv::imshow("hello",mat);
return a.exec();
}
What im doing wrong?
Imo the problem is not in your code, I just run it (using Qt5.5, Win10, openCV 4 and mingw64), even if I had to change cvNamedWindow to cv::namedWindow.
I have two hints:
did you build openCV with mingw64? If not, do so.
are the openCV dlls in the path when you run the application? You can also copy all opencv dlls in the program folder to check that quickly...
I'm a beginner in working with CGAL libraries , I tried to run a combinatorial map example qt-creator on fedora after combiling CGAL:
#include <QCoreApplication>
#include <CGAL/Combinatorial_map.h>
#include <iostream>
#include <cstdlib>
typedef CGAL::Combinatorial_map<3> CMap_3;
typedef CMap_3::Dart_const_handle Dart_const_handle;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
CMap_3 cm;
// Create two tetrahedra.
Dart_const_handle dh1 = cm.make_combinatorial_tetrahedron();
Dart_const_handle dh2 = cm.make_combinatorial_tetrahedron();
// Display the combinatorial map characteristics.
cm.display_characteristics(std::cout);
std::cout<<", valid="<<cm.is_valid()<<std::endl;
unsigned int res = 0;
// Iterate over all the darts of the first tetrahedron.
// Note that CMap_3::Dart_of_orbit_range<1,2> in 3D is equivalent to
// CMap_3::Dart_of_cell_range<3>.
for (CMap_3::Dart_of_orbit_range<1,2>::const_iterator
it(cm.darts_of_orbit<1,2>(dh1).begin()),
itend(cm.darts_of_orbit<1,2>(dh1).end()); it!=itend; ++it)
++res;
std::cout<<"Number of darts of the first tetrahedron: "<<res<<std::endl;
res = 0;
// Iterate over all the darts of the facet containing dh2.
for (CMap_3::Dart_of_orbit_range<1>::const_iterator
it(cm.darts_of_orbit<1>(dh2).begin()),
itend(cm.darts_of_orbit<1>(dh2).end()); it!=itend; ++it)
++res;
std::cout<<"Number of darts of the facet containing dh2: "<<res<<std::endl;
return a.exec();
}
.pro file:
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp
INCLUDEPATH += /usr/include
LIBS += -lgmp -lmpfr -lCGAL
but it shows the following error:
In file included from /usr/include/c++/7/bits/stl_algo.h:59:0,
from /usr/include/c++/7/algorithm:62,
from /usr/include/QtCore/qglobal.h:68,
from /usr/include/qt5/QtCore/qcoreapplication.h:43,
from /usr/include/qt5/QtCore/QCoreApplication:1,
from ../untitled/main.cpp:1:
/usr/include/c++/7/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
I searched about the problem , but nothing is working with me
I appreciate any help
thanks
I solved it by removing INCLUDEPATH += /usr/include from .pro file
I got an solution: replace all #include_next with #include.
My goal is to run a simple OpenCV contribute (extra) module in Qt 5.5.1.
Steps:
1) created a Qt Application app;
2) changed the main.cpp file to :
#include <QApplication>
#include <opencv2/core/utility.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <cstring>
#include <QDebug>
using namespace std;
using namespace cv;
int main(int argc, char*argv[])
{
qDebug() <<"start!" << endl;
QApplication a(argc, argv);
string trackingAlg = "KCF";
MultiTracker trackers(trackingAlg);
qDebug() <<"success!" << endl;
return a.exec();
}
and here is my .pro file:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = tracker4
CONFIG += c++11
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /usr/local/include/opencv
LIBS += `pkg-config opencv --libs`
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_videoio -lopencv_tracking
The program compiles successfully, but in the runtime, it crashes without even running the main() function. I don't get such an error when I run this in Code::Blocks but in Qt I still have this issue.
I am using Qt 5.5.1 and Ubuntu 14.04.
Can anyone generate this "seg fault" error in his/her machine?
For QT 5, build the OpenCV with QT=OFF.
For QT 4, build the OpenCV with QT=ON.
I am running QtCreator on Mac... I want to start working on boost libraries ... So, I installed boost libraries using
brew install boost
After that I created a small boost hallo world program and made the changes in .pro file as follows
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
unix:INCLUDEPATH += "/usr/local/Cellar/boost/1.55.0_1/include/"
unix:LIBPATH += "-L/usr/local/Cellar/boost/1.55.0_1/lib/"
SOURCES += main.cpp
LIBS += \
-lboost_date_time \
-lboost_filesystem \
-lboost_program_options \
-lboost_regex \
-lboost_signals \
-lboost_system
I am still unable to build... What could be the reason? Please suggest me what could be the possible mistake...
The errors are
library not found for -lboost_data_time
linker command failed with exit code 1 (use -v to see invocation)
This is taking a bit from Uflex's answer, as he missed something.
So keep the same code:
//make sure that there is a boost folder in your boost include directory
#include <boost/chrono.hpp>
#include <cmath>
int main()
{
auto start = boost::chrono::system_clock::now();
for ( long i = 0; i < 10000000; ++i )
std::sqrt( 123.456L ); // burn some time
auto sec = boost::chrono::system_clock::now() - start;
std::cout << "took " << sec.count() << " seconds" << std::endl;
return 0;
}
But lets change his .pro a bit:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
macx {
QMAKE_CXXFLAGS += -std=c++11
_BOOST_PATH = /usr/local/Cellar/boost/1.55.0_1
INCLUDEPATH += "$${_BOOST_PATH}/include/"
LIBS += -L$${_BOOST_PATH}/lib
## Use only one of these:
LIBS += -lboost_chrono-mt -lboost_system # using dynamic lib (not sure if you need that "-mt" at the end or not)
#LIBS += $${_BOOST_PATH}/lib/libboost_chrono-mt.a # using static lib
}
The only thing I have added to this was the boost system( -lboost_system )
That should solve the issue with his original version causing the undefined symbols, and allow you to add your other libraries.
Such as -lboost_date_time, which for me worked perfectly with the brew install.
Granted, my path is actually: /usr/local/Cellar/boost/1.55.0_2
Boost libraries are modularized, you just need to link against the libraries that you are using. Some libraries are header only, so you don't need to do anything, having boost reachable in your path is enough.
You can try to compile this:
//make sure that there is a boost folder in your boost include directory
#include <boost/chrono.hpp>
#include <cmath>
int main()
{
auto start = boost::chrono::system_clock::now();
for ( long i = 0; i < 10000000; ++i )
std::sqrt( 123.456L ); // burn some time
auto sec = boost::chrono::system_clock::now() - start;
std::cout << "took " << sec.count() << " seconds" << std::endl;
return 0;
}
And in the .pro file:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
macx {
QMAKE_CXXFLAGS += -std=c++11
_BOOST_PATH = /usr/local/Cellar/boost/1.55.0_1
INCLUDEPATH += "$${_BOOST_PATH}/include/"
LIBS += -L$${_BOOST_PATH}/lib
## Use only one of these:
LIBS += -lboost_chrono-mt # using dynamic lib (not sure if you need that "-mt" at the end or not)
#LIBS += $${_BOOST_PATH}/lib/libboost_chrono-mt.a # using static lib
}