PDA

View Full Version : how to use macros in Qtwidget



iswaryasenthilkumar
8th January 2015, 04:27
am having coding below
QString configpath("/home/ishwarya/display_images");
i should not use this path directly in coding , i have to give in macros.
can any one please guide to me to do macros.:confused:
Thanks in Advance

ChrisW67
8th January 2015, 08:37
Looks like a school question on C++ programming (that has nothing at all to do with Qt). Perhaps you should consult your text books or a basic C or C++ tutorial (http://www.learncpp.com/cpp-tutorial/110-a-first-look-at-the-preprocessor/)?

jefftee
9th January 2015, 20:01
am having coding below
QString configpath("/home/ishwarya/display_images");
i should not use this path directly in coding , i have to give in macros.
can any one please guide to me to do macros.:confused:
Thanks in Advance
I suspect what you're looking for is something like this in a header file:


#define CONFIG_PATH "/home/ishwarya/display_images"


and then in your cpp file:


QString configpath(CONFIG_PATH);

This approach would allow you to reference the config path anywhere in your code and if you need to change it, you only need to change the define statement in the header file. That said, it really sounds like your config path should either be specified via user input or specified programattically rather than hard coded. There certainly is not a "/home/ishwarya/display_images" folder on anyone else's system.

Good luck.

iswaryasenthilkumar
16th February 2015, 12:45
i have to define text file in #define.
i defined
#define "/home/ishwarya/display_images/DI_config.txt"
bt this line shows an error ,,
can any one give suggestion for this
Thanks in advance

I suspect what you're looking for is something like this in a header file:


#define CONFIG_PATH "/home/ishwarya/display_images"


and then in your cpp file:


QString configpath(CONFIG_PATH);

This approach would allow you to reference the config path anywhere in your code and if you need to change it, you only need to change the define statement in the header file. That said, it really sounds like your config path should either be specified via user input or specified programattically rather than hard coded. There certainly is not a "/home/ishwarya/display_images" folder on anyone else's system.

Good luck.

wysota
16th February 2015, 14:06
This is not C++ kindergarden and your question has no relation to Qt.

I can only say the define statement you posted makes no sense syntax-wise.

ChrisW67
16th February 2015, 20:03
... And you even quoted the text that shows exactly how it should be used in this thread