Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I don't understand why my program segfault after #define with that :
if(QProcess::systemEnvironment().filter("toto").size() == 1 )
if(!QProcess::systemEnvironment().filter("toto").at(0).contains("13"))
#define tata
I using this code in another class and he run like a boss :P
The program segfault when the if is false...
I know #define is a precompiler directive and I understand the segfault but why this same code run in my another class with no problem and if my environment variable is changed the program accept the modification.. and I specified that the code has not been recompiled..
#define is a precompiler directive, it is parsed and used by the compiler, not at runtime. So it does not obey your if conditions. Thus, your if is actually conditioning the execution of whatever goes after this code... whatever it is.
Solution: use a boolean variable, not a macro.
bool tata = false;
if(QProcess::systemEnvironment().filter("toto").size() == 1 )
if(!QProcess::systemEnvironment().filter("toto").at(0).contains("13"))
tata = true;
But the details will depend on what you are doing with tata in the first place.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 15 days ago.
Improve this question
My project is compiling and opening up on the web but the main loop is not working. The error seems to be that usleep is undefined. I'm not sure how I can correct this. As per the error message, I seem to be dividing by zero (undefined). I tried removing 'fps' but no luck.
#define emscripten_set_main_loop(func,fps,simulateInfiniteLoop)
while (1) { func(); usleep(1000000/fps); }
Expands to:
while (1) { loop(); usleep(1000000/0); }
identifier "usleep" is undefined C/C++(20)
Problem solved! I switched over to using emscripten_set_main_loop_arg, put all my variables in a struct, and rewrote my functions to accept pointers to the struct and deal appropriately.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
I'm trying to modify an application I've completed in QT Creator so that it can be run within a browser. The majority of code in qopenglfunctions_3_2_core.h is skipped because opengles2 is defined in the following line.
#if !defined(QT_NO_OPENGL) && !QT_CONFIG(opengles2)
/*
The QT_CONFIG macro implements a safe compile time check for features of Qt.
Features can be in three states:
0 or undefined: This will lead to a compile error when testing for it
-1: The feature is not available
1: The feature is available
*/
#define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
With clang, QT_CONFIG(opengles2) returns 0 and the statement evaluates to true. With emscripten, QT_CONFIG(opengles2) returns 1 and the statement evaluates to false which skips the remainder of the file. I'm trying to find a workaround.
Changing
#include <QOpenGLFunctions_3_2_Core> to #include <QOpenGLFunctions_ES2> resolved the issue for me. However it seems there were some variables that did not carry over such as
GL_LINE_SMOOTH
glVertexAttribIPointer
glPointSize
If anyone knows of a fix to this please let me know. In the meantime, I'll keep digging around.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to write code like this MAKE var=NUMBER: 21, which can be translated to
auto var=21;.
I have defined the following macros: #define MAKE auto and
#define NUMBER (1==0)? , but they did not work well.
To put it simple, I would like to add the semicolon at the end of the definition automatically.
Thanks.
It is not achievable with C++ macro syntax. You have only macro before 21 and not after. Though you can achieve that if you change your syntax slightly:
MAKE var=NUMBER(21)
instead of
MAKE var=NUMBER: 21
and define NUMBER as:
#define NUMBER(x) (x);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to expand my knowledge of conditional statements in C++
if (condition){
return 0;
}
if else (condition A && condition B) {
//
}
else {
//
}
in this multiple conditonal state, what would be a good alternative?
Obviously because of condition A && condition B on if else statement, I can't use switch statement?
what would be a good alternative?
Shouldn't matter if no good alternative is better than what you already have.
(Ignoring the apparent if else error) Your shown control flow appears to be quite minimal (and therefore good) representation. There is no code duplication, and no repetitive structure that could be further exploited.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm new to C++ and currently I'm using Code::Blocks to run my code. So, I wonder if i can set up timer until a code is executed because i need timer to make my program looks better. Any answers is accepted ^^
I wrote a timer class long ago. You can find the complete code on Github here: timer
It is a complete example with Makefile as well.
Note: You will need the ability to compile C++11.
You can create a class for this purpose. In constructor and destructor get the current time. You only need to subtracts them to get the elapse time of each functions including main.
http://en.cppreference.com/w/cpp/chrono