A simple phonebook using FLTK in c++ - c++

Hi guys I want to make a phone book in c++ using FLTK as a part of my project. It should have options to add, delete,modify and search the numbers.
Since I am new to FLTK can some one suggest which widgets should I use and how?
Also I am planning to write the contents of phonebook into a text file whose entries will be retrieved/ written into as and when required. So non graphical code is easy . Can some suggest how do I integrate graphics into this using FLTK?
Thanks in advance

I'd suggest you first draw a sketch of the user interface in a paper. Like this for instance :
Then you go here : http://www.fltk.org/doc-2.0/html/index.html and find the names of the widgets you need. Optionally, do the Hello World example so that you understand how FLTK is compiled into a C++ program. Some hints : you want a button for Add, Modify and Delete, an input for the Find and for editing the details of each entry plus a select browser for the list of names.

Related

Editing plist from c++ code

So I have a code written in c++. I am trying to get a user's preference through an application. Depending on the sent value, I need to update a key in the plist. I can't find any way to do so in C++. Any suggestions?
You can edit a plist by executing plistbuddy command using system() call. An example to add a key value pair to plist file using system() is given below.
system("/usr/libexec/PlistBuddy -c \"Add :ASSET_ID string '1'\" \"/Library/Application Support/MyApp/ABC.plist\"");
Given below is the plistbuddy command given to system call.
/usr/libexec/PlistBuddy -c "Add :ASSET_ID string '1'" "/Library/Application Support/MyApp/ABC.plist"
More details on plistbuddy here - https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/PlistBuddy.8.html
I am guessing a few things here, because from your questions it is not quite clear the setup you are working with. I'm assuming you have a cocoa app with part of the code written in c++ (maybe based on some third party GUI library, e.g. FLTK, that hides the obj-C part?).
Anyway, in my opinion the best and safest way to go about this kind of things is to write small c++ wrappers for objective-c/cocoa code in a .mm file. You can then use the proper cocoa facilities to robustly locate and manipulate the plist (your probably want to look inside NSBundle and NSPropertyListSerialization in your case).

How to choose and open a file during runtime with C++?

At the moment I am creating an Editor for Textures and I want to choose the textures during runtime. Later I would like to choose the save directory for new textures.
I found the
How to: Open Files Using the OpenFileDialog Component. But I think this is not the solution.
(assuming you are on Windows, pas per screenshot)
If you simply want to select a folder, you can use SHBrowseForFolder.
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762115%28v=vs.85%29.aspx
M.
You need to look at the Common Dialog Library.
http://msdn.microsoft.com/en-gb/library/windows/desktop/ms645524(v=vs.85).aspx
Or, if you are only interested in Vista/Windows 7 support, you could consider the Common Item Dialogs instead.
http://msdn.microsoft.com/en-gb/library/windows/desktop/bb776913(v=vs.85).aspx
For 'native' C++ you wouldn't be able to easily use the .NET components that your link refers to.
I have solved my problem with using the dirent.h file. I have acknowledge of this file by founding this post How can I get the list of files in a directory using C or C++?
I have write my own fileexplorer by using dirent.h and SFML.
Sorry if i can't illustrate my problem.
but thanks for the replies (:

Generalizing a User Interface of an application

I am working in C language and creating applications for an embedded device. These applications mainly
include capturing data and storing it into a database for performing an enrollment. This involves lot of
widgets like frames, buttons, check-boxes, radio buttons, widget list boxes, text boxes, entries, combo boxes etc. All these widgets are being created using the X library.
I have tried to make the application generalized using CSV files, having a list of all the widgets that the user wants to create and then creating those widgets accordingly based on the information mentioned
in the CSV file.
The CSV file that I am creating includes things like
Widget name
Widget type
Widget data input type/max length / min length
.....
..... etc.
Please suggest some other ways or how can I improve the current way itself?
I am also creating the DB by the information provided in the CSV itself. I can say that it's
a "Data Driven User Interface" approach. I need some suggestions. Please provide me
some good suggestions.
Platform: Linux, GCC compiler
Maybe not quite what you are looking for but WxWidgets has a format called XRC. It's windows described as XML: http://docs.wxwidgets.org/2.9.4/overview_xrc.html. Are you really writing your GUI in C? I guess that might be a constraint on an embedded product.
Anyway, you might get good ideas from the site. I haven't used it so no specific feedback is available from me.

How to make a GUI out of a already done code in C++

I want to make a GUI . I have a code that runs, made in C++. The project is made in Visual Studio(Visual C++ 2010 Express).
The outputs now are printed in command line. I want to tranform this to be printed to a window.
Is there a way to do this in this already made project ? Or I have to make a new one.
P.S. The code is consists of many, about 20 .cpp files and about 5 .h headers.
Following my comment on your original post here's some more information that will help you get through this:
Simply turn your "cout << ...." calls (or printf if the code is
actually C) to append the text to the UI control you want the output
to be displayed in? Or you can check this "hack" out:
cplusplus.com/forum/general/27876
Now simply add a new source file to the project: call it.. MyProjectGUI.cpp
Follow this guide here to setup the window on your project:
http://msdn.microsoft.com/en-us/library/bb384843.aspx
Then go through the rest of your code (or use the hack mentioned above or some kind of pipe to redirect your output (probably a lot! more complicated than the following method) and simply replace your cout << / printf calls with something like what's detailed in here: http://www.programmersheaven.com/mb/windows/105327/105327/appending-text-to-edit-control/
You'll find the basic idea of your modifications to be along these lines:
Create a simple window
Add a new edit field to the window (http://en.wikibooks.org/wiki/Windows_Programming/User_Interface_Controls and http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85).aspx)
Replace all console printing calls with a call to your append function for the edit box in the GUI
Best of luck with this (I might write up some code if I'm bothered but don't count on it -> no time. You should be able to figure it out with what I've posted though)
You dont have to do another project. It is enough to include headers and add libraries to linker. You should try a QT which is portable, well written and easy to learn. My one advice is to stay as portable as possible, in example you can create a makefile for your project so add new libraries will be a quiet easy job and not related to IDE . Dont stick to one environment.

how to write and read a text to and from a LineEdit using QT Creator?

I am working with QT Creator. I have a form that contains a push button and an Line Edit. I would like to print a string that i give programatically in this LineEdit.Secondly I would also like to the from the LineBox a string that I fill in and print it using QMessageBox.
How to do it? Need some help. I don't know how to access the displayText() to write and read from a LineEdit.
I would like to specify that I put the push button and the lineedit on the Form using drag and drop.
I am working in c++ under Ubuntu
Appreciate.
You use QLineEdit::setText() to change the text and QLineEdit::text() to read.
Your questions are very basic and show a clear lack of studying the documentation and experimenting thing yourself. Qt is one of the better documented frameworks out there and with lots of examples. Please take your time to go through them.