|
Is Code:Blocks good for this purpose? Can I create elegant GUIs using it?
|
|
|
|
|
I had to look up Code::Blocks and noticed that it incorporates wxWidgets. I don't develop GUI apps, but when I looked into the area a while ago, I bookmarked wxWidgets so I could return to it if I ever needed to. C++ doesn't have a GUI library, so you have to find one. And if you want to support different platforms, not just Windows, you need something like wxWidgets, not WPF.
As far as an IDE goes, VS2022 (Community Edition) is free and an excellent IDE. You can probably develop using wxWidgets within VS2022, but you'd likely have to spend some time configuring it, whereas Code::Blocks looks like it should work immediately. But I know next to nothing about this, so you need to get input from someone who does.
|
|
|
|
|
|
Perhaps poorly worded. Not part of the C++ standard, in the same way that it doesn't have sockets.
How many platforms does Windows Controls support?
|
|
|
|
|
I take your points. But C# does not have those features either, as part of the standard. The libraries are implemented in the same way that the Win32 or MFC libraries are.
Yes, Windows controls only work in the Windows OS.
|
|
|
|
|
Is it possible to have relative element position in C++ GUI (using visual studio) like what we have in WPF?
|
|
|
|
|
No, you have to do the layout calculations yourself. And TBH if GUI applications are your main focus then I would suggest you stick to .NET with C# or VB.NET.
|
|
|
|
|
I'd only heard of VS2022, so I had to do a search on the others. I assumed that your response meant that the others were no longer in business, but they still seem to be undergoing development.
|
|
|
|
|
When your project is causing you enough headake on its own, last thing you want is errors because of a buggy IDE/compiler.
There is no serious match for VS from what I know.
|
|
|
|
|
Qt Creator is worthwhile ONLY if you embrace Qt. Qt is great but is like its own OS. I still vastly prefer Visual Studio and so did my Qt development with it. Had I ported my last app to Linux, only then would I use Qt Creator.
Don't bother with Code::Blocks. It's adequate for Linux but a waste of time for Windows. Moreover, for Linux CLion is vastly superior.
|
|
|
|
|
Visual Studio is always the best choice for creating Win32 GUI applications as it integrates all the tools you will need. It also includes a simple template to create your first GUI program (although it is a bit clunky). And the standard Windows Controls - Win32 apps | Microsoft Docs[^] cover most control types you are likely to need.
|
|
|
|
|
With no prior baggage, I would think that WinUI 3 and VS2022 (with C++) would be the route.
About WinUI
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I will start with my code:
template < typename T1, typename T2 >
void printvector(T1& fout, const std::vector < T2 >& V)
{
if (V.empty()) fout << "EMPTY\n";
else {
for (size_t x = 0; x != V.size() - 1; ++x)
{
fout << V[x] << ", ";
}
fout << V[V.size() - 1] << '\n';
}
}
fstream StatFile;
StatFile.open(STATICFILE, std::fstream::out);
if (StatFile.is_open())
{
for (i = 0; i != NewLandmarks.size(); ++i)
{
cout << NewLandmarks[i].name << " "; printvector(cout, Subtractions);
StatFile << NewLandmarks[i].fiducial << ", " << NewLandmarks[i].name << ", "; NewLandmarks[i].location.print(StatFile);
if (Subtractions.empty()) StatFile << "\n";
else {
StatFile << ','; printvector(StatFile, Subtractions);
}
}
StatFile.close();
}
The template is supposed to print out the contents of a vector, either to the console when given cout, or to a text file when given an fstream variable.
NewLandmarks is a vector of a struct and that seems to be working just fine here.
Subtractions is a vector of size_t, and this is where the problem lies.
When the code runs, the NewLandmarks name is printed to the console, as well as the contents of the Subtractions vector, which in this case is always 45, 46, 47, 48
When the code gets to the next line, where it prints to the file, NewLandmarks.fiducial, NewLandmarks.name and NewLandmarks.location.print(StatFile) all work as expected.
However, the Subtractions vector only prints its last element, 48, to the file. This implies that the Subtractions vector somehow got changed by the printvector template. But, I don't see how, or why.
Even more confusing, this code loops several times. The first time Subtractions prints to the file as 48. The second time it prints as 47, 48. The third time as 46, 47, 48. I don't loop through a fourth time, but I think I can see what would happen. But I still don't know why. Even worse, during each of these loops when Subtractions is printed to the console I always get the full vector: 45, 46, 47, 48.
So,
Why is the template function behaving differently from its console and file printing activations?
Why does the template function write only the last element of the vector to the file and its first iteration?
Why does the template function change behavior and write an additional vector element each time it runs?
In case it is relevant, NewLandmarks.location is a Vector (a mathematical Vector class that I created) and its print function looks like this:
(L is the length of the Vector)
void Vector::print(std::fstream & fout) const {
for (size_t i = 0; i != L; ++i) {
fout << std::setprecision(15) << std::setw(22) << v[i];
if (i != L - 1) fout << ',';
}
}
Even if this is somehow causing my problem, I still do not see how or why. But, it seems to be working fine.
Thank you for your help
|
|
|
|
|
|
Yes, or that is what I am in the process of doing. I found this unexpected behavior and I do not know why it happens or how to fix it.
|
|
|
|
|
Probably there is part of your code (not posted here) messing up with the Subtraction vector.
This code
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
template < typename T1, typename T2 >
void printvector(T1& fout, const std::vector < T2 >& V)
{
if (V.empty()) fout << "EMPTY\n";
else {
for (size_t x = 0; x != V.size() - 1; ++x)
{
fout << V[x] << ", ";
}
fout << V[V.size() - 1] << '\n';
}
}
int main()
{
vector <size_t> sub {46,47,48};
printvector(cout, sub);
fstream foofile("foo.txt", ios::out);
if (foofile)
{
printvector(foofile, sub);
}
} produces the same output
46, 47, 48 both to the console and to the foo.txt file.
[update]
Note, you might also write
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
template <typename T>
ostream & operator<< (ostream & os, const vector <T> & v)
{
if ( v.empty() ) os << "EMPTY\n";
else
{
for (size_t n = 0; n != v.size() - 1; ++n)
{
os << v[n] << ", ";
}
os << v.back() << '\n';
}
return os;
}
int main()
{
vector <size_t> sub {46,47,48};
cout << sub;
fstream foofile("foo.txt", ios::out);
if (foofile)
{
foofile << sub;
}
} [/update]
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
modified 24-May-22 6:02am.
|
|
|
|
|
That is what I thought at first. But why does the vector print correctly when it is to the console and incorrectly when it is to a file, and the two commands are right next to each other. Where was the opportunity to screw up the Subtractions vector?
|
|
|
|
|
You only, having the full code, might know.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
I just ran the above code and it works correctly. I had to create my own version of the NewLandmarks structure, so maybe what you have is actually the issue.
|
|
|
|
|
Here is my struct and the NewLandmarks vector. Do you see anything in this code that could be causing this problem?
struct landmarktype {
std::string fiducial{};
std::string name{};
Matrix location{};
std::vector <size_t> subtractions{};
};
vector <landmarktype> NewLandmarks;
declared earlier in the code, but in case it's important here is my Matrix class:
class Matrix {
private:
double * M;
size_t ROWS, COLUMNS;
public:
Matrix(): M(NEW double[1]), ROWS(1), COLUMNS(1) {}
Matrix(size_t R, size_t C): M(NEW double[R * C]), ROWS(R), COLUMNS(C) {}
~Matrix() {delete[] M;};
Matrix(const Matrix & m): M(NEW double[m.ROWS * m.COLUMNS]),
ROWS(m.ROWS), COLUMNS(m.COLUMNS) {
for (size_t i = 0; i != (ROWS * COLUMNS); i++) M[i] = m.M[i];
}
double & operator()(const size_t R,
const size_t C);
double operator()(const size_t R,
const size_t C) const;
[[nodiscard]] size_t rows() const { return ROWS; }
[[nodiscard]] size_t cols() const { return COLUMNS; }
void set(const size_t R, const size_t C) {
double* newMat = NEW double[R*C];
delete[] M;
M = newMat;
ROWS = R;
COLUMNS = C;
}
void clear()
{
double* newMat = DBG_NEW double[0];
delete[] M;
M = newMat;
ROWS = 0;
COLUMNS = 0;
}
void print(std::fstream & ) const;
}
void Matrix::print(fstream & fout) const {
size_t r, c;
for (c = 0; c != COLUMNS; ++c)
for (r = 0; r != ROWS; ++r)
{
fout << setiosflags(ios::fixed) << std::setprecision(outputprecision) << std::setw(22) << M[r * COLUMNS + c];
if ((r*COLUMNS+c) != (ROWS*COLUMNS - 1)) fout << ", ";
}
}
|
|
|
|
|
I cannot get that to build, the compiler does not know NEW or DBG_NEW . But either way that is a rather complex class. However, I can see nothing obvious, I guess the only way to find the problem is via the debugger.
[edit]
OK, with a bit of editing I got it to work and the output is correct (as far as I can see) in both cases.
So the issue must have something to do with what you are running, or your data.
[/edit]
|
|
|
|
|
Sorry, my mistake. That's my attempt at some debugging.
When I switch debugging off the preprocessor will replace NEW and DBG_NEW with new. Do that now and it should compile.
|
|
|
|
|
See the update in my previous message.
|
|
|
|
|
Hello,
We have an application. We want to check while starting that application in any system (customer place) whether any virus is there or not or the exe went out with or without virus.
Can we do this in C++ in the application startup itself or can we use any third party software?
Please suggest.
Regards,
Gopinath.
|
|
|
|
|
Gopi Nath wrote: Can we do this in C++ in the application startup Not unless you know how to write a virus check program, and have a database of all known viruses.
|
|
|
|
|