How to get started with IDEs, Especially Qt Creator? - c++

I'm a highschool student, who have only ever coded in Turbo C++. I have no idea how IDEs work, I installed Qt Creator to start learning GUI programming but I can't even get it to run a simple C++ code. I doesn't know what files to include.
NOTE: I'm a total newbie.
The tutorials I found on YT are confusing and not clear. I have no idea why this is happening. This is my code:
#include<IOSTREAM.H>
#include<CONIO.H>
void main() {
clrscr();
cout << "Hello World!";
getch();
}
I did build all, then run but I got this Issue:
No rule to make target `all'. Stop.
Screenshot of Qt Creator

clrscr() is Windows specific (or is it Turbo C++ specific - I forget), in any case; don't use it.
cout should be std::cout.
you should include "iostream" not those obsolete ".h" versions (besides, the header names are lowercase, not uppercase).
void main is not valid. main always returns int.
Note: these bugs have nothing to do with Qt nor qtcreator. They are just, plain and simple, bugs in your code. Read Qt documentation and try out some tutorials.

Related

circle.exe Stopped working while using graphics.h in codeblocks

I am using Code::Blocks 16.01 for coding in C++ every code runs properly without showing any problem or error. But ever I runs a graphics program it shows a pop-up window with message circle.exe has stopped working(circle.cpp is the name of my program)(had already copied graphics.h ,winbigim.h and libbgi.a and also corrected the line 302 error in graphics.h and had also had done the linking work).
code that i am using is:-
//circle.cpp
#include <graphics.h>
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
circle(100,100,50);
getch();
closegraph();
return 0;
}
it shows a pop-up window with message circle.exe has stopped working.
But when ever I run the same code in Turbo C++ it runs without any problem/error.
What should I do?
It is because the BGI graphics expect powers that modern systems don't give out willy-nilly anymore.
To use the old library, your options are:
(1) Run your program in DosBox, and x86 emulator
Dos Box
The other option are to get a modern graphics library, like SDL(It's better way and I suggest you).

Unable to use graphic programming in codeblock

#include<graphics.h>
#include<conio.h>
#include<iostream>
using namespace std;
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:\\TC\\BGI" );
cout<<"Please Enter to continue..."<<endl;
getch();
closegraph();
return 0;
}
All other programmes are running fine on my Codeblock 13.12, but when I run a simple graphic programme compiler crashes giving pop up window that says:
"graphic.exe has stopped working window is checking solution".
It also giving a warning message on compilation:
warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
How to resolve it?It is due to turbo C.
It is due to turbo c.
Turbo c/c++ is ancient and didn't conform any standards. There are no such header files like conio.h or graphics.h for any modern c++ compilers.
Your codeblocks IDE most probably uses the GCC toolchain by default, which doesn't provide these headers.
You should lookup for more modern 3rd party libraries for handling graphics and raw keyboard input (e.g. something like SFML). The c++ standards have no notion about such stuff so far.
For Graphics Programming In C You Need To Install Codeblocks-EP Version. Download From Here http://codeblocks.codecutter.org/setup.exe
Install And Then Go File>New>Project>Winbgim project>GO>>Add Console>>NEXT . Give Project Name,location path And Click Finish. Now Again File >New>Empty File
Write Your C graphics Code>> Build And Run.
This Codeblocks has pre installed built in graphics libraries. So You need not to add anything.

C++: Why does libtiff break the console-output?

So finally I’m not able to help myself out by researching anymore. Hopefully you can help me.
I recently decided to learn C++ in the context of my bachelor-thesis: My first aim is to read the pixel-values of a tiff-image with the libtiff-library. Yet, every call of a function of the library seems to break parts of my program.
Here’s the simple “HelloWorld”-Program, it works as it should:
#include "tiffio.h"
#include <iostream>
using namespace std;
int main() {
cout << "Hello" << endl;
// TIFF* tif = TIFFOpen("path to .tif", "r");
return 0;
}
When I uncomment the second line in main(), the code still does compile without errors (except the warning that ‘tif’ isn’t used) and I can start the program as usual. Yet nothing gets printed into the console anymore. Not “Hello” nor any errors.
Any suggestions where the error could be? The code should be alright, I guess I messed something up during the setup of the library or so. Here’s what I did:
I managed to set up eclipse (Mars, 32bit) for C++ and MinGW (32bit) on my 64bit Win7, then downloaded libtiff 4.0.4 and built it following this instruction.
I created a new C++-project with the mentioned code and did the following adjustments in the project-properties:
Project->Properties->C/C++ General->Paths and Symbols->Library
Paths-> Added “D:/… /tiff-4.0.4/libtiff/.libs”
Project->Properties->C/C++ Build->MinGW C++
Linker->Miscellaneous->Set Linkerflags to “-static-libgcc
-static-libstdc++”
Project->Properties->C/C++ Build->MinGW C++ Linker->Libraries-> Set
(-L) to “D:/… /tiff-4.0.4/libtiff/.libs” and (-l) to “libtiff”
I know the .tif is a valid file as I implemented parts of my program in C#, using the LibTiff.NET library by BitMiracle.
Thank you in advance!
Edit 1: The same error occures, even if TIFF* tif = TIFFOpen("path to .tif", "r"); is never called but written down in a dead part of the code. Debugging does not work either, the program seems to be terminated (exit value 0) before a single line is executed, without any error-reports.
I had the same issue and managed to get rid of it.
I set up eclipse (Mars) for C++ and MinGW on my 64bit Win7, then downloaded libtiff 4.0.4 and built it following this instruction.
After the build, I got two directories containing files:
include
tiff.h
tiffconf.h
tiffio.h
tiffio.hxx
tiffvers.h
lib
libtiff.a
libtiff.dll.a
libtiff.la
libtiffxx.a
libtiffxx.dll.a
libtiffxx.la
I also linked all include files and only the libtiff.a to my project and that solved it, ie, the other lines are now executed.
I hope, I helped with this post.

Simple C++ program using pqxx (postgres)

I'm trying a very basic C++ program using Code::Blocks. I'm on Ubuntu 12.04 and installed pqxx from the software manager. Here's the code.
#include <pqxx/pqxx>
#include <iostream>
using namespace std;
int main()
{
pqxx::connection MyConn ("dbname=dbESM user=postgres");
cout << "Hello world!" << endl;
return 0;
}
But I get the following error on hitting F9 to compile and run:
/usr/include/pqxx/connection.hxx|87|undefined reference to
`pqxx::connectionpolicy::connectionpolicy(std::basic_string, std::allocator > const&)'
The above message is from the file connection.hxx and the line highlighted is this:
explicit connect_direct(const PGSTD::string &opts) : connectionpolicy(opts) {}
The connection.hxx file is not mine - I think it's part of pqxx.
I'm pretty new to this platform so I'm avoiding the terminal to compile code. Any help would be greatly appreciated.
You need to add the reference to the libpqxx library to the project.
Inside Code::blocks, when the project is open, locate Project in the menus, then follow Build options, then open the tab called Linker settings, then hit Add, then enter pqxx.
If you were using the libpq C library instead, the procedure would be identical except the name would be pq.
You need to link against the according library, just #including the header files isn't enough. If available, you could use pkg-config to determine the according libraries. Further, what IDE are you using? Without that, the "on hitting F9" reference is useless. Also, compiling this on the commandline might even be easier, since it is clearer what exactly is happening.

Codeblocks outputs broken executable

I have downloaded plenty of different versions of code blocks, and none of them compiles quite right. My hello world runs within code blocks just fine. However, when I run the executable outside of codeblocks, it says "Hello.exe has stopped working". There isn't anything wrong with my code (I don't think.) and my mingw compiles fine outside of codeblocks. What does codeblocks do to my executable? Is there some option to fix this? I am on windows 7 64 bit, and my current code blocks version is 10.05. My program:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
cin.ignore();
return 0;
}
I solved the problem. I had a broken compiler (or something like that). My suggestion for other people with this problem is to experiment with different versions of the minGW compiler. Also, change the version of code blocks you are using, or even uninstall everything and restart. The problem with mine was I downloaded a bad compiler. [The truth is, codeblocks isn't the best ide.]