c++,qt,codeblocksRelated issues-Collection of common programming errors
djeidot
c++ sockets networking
In C++, what’s the easiest way to get the local computer’s IP address and subnet mask?I want to be able to detect the local machine’s IP address in my local network. In my particular case, I have a network with a subnet mask of 255.255.255.0 and my computer’s IP address is 192.168.0.5. I need to get these had two values programmatically in order to send a broadcast message to my network (in the form 192.168.0.255, for my particular case)Edit: Many answers were not giving the results I expected b
TooTone
c++
The following code produces a compiler error: ‘BaseTest::_protMember’ : cannot access protected member declared inclass ‘BaseTest’Why can’t I access the member variable _protMember in my class SubTest even though it is protected?class BaseTest { public:BaseTest(){};BaseTest(int prot){_protMember = prot;};protected:int _protMember; };class SubTest : public BaseTest {// followup questionSubTest(const SubTest &subTest){_protMember = subTest._protMember; // this line compiles without error};Sub
jgauffin
c++ windows-xp boost-asio multicast sender
I’m trying to use boost.asio to implement a multicast sender. I have a my thread implementation and I need my boost.asio only for management of the socket.I looked at the example on the site of boost but I did not understand and I do not Compile. Where can I find what I need?The complile errors are: (I have tried this example: http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/multicast/sender.cpp)Error 3 error C2653: ‘asio’ : is not aclass or namespace name c:\Documentsand Se
genpfault
c++ opengl-es android-ndk
I’m writing a native app that should only display a little triangle with a texture. But unfortunately, it everytime only displays a white triangle. My code is very simple.First to load a tga Image: static const GLenum gl_format[4] = { GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA };unsigned int LoadTGATextureFromFile(const char* filename) {unsigned int handle;unsigned char hdr[18];unsigned char file_id[256 + 1];int file;file = open(filename, O_RDONLY);if(file < 0){Log(LOGLEVEL_ERROR, APP
sth
c++ arrays string
I’m working on a program for class that takes in a number from 0 to 9999, and spits out the word value (ie 13 would be spit out as “thirteen”, etc) And I’m having a pain with the array for some reason.Here is the class so far:#include<iostream> #include<string>using namespace std;class Numbers {private:int number;string lessThan20[ ] = {“zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”, “ten”, “eleven”, “twelve”, “thirteen”, “fourteen”, “fifteen”, “sixte
Mehrdad
c++ c
I tested right shift with Visual Studio, Ubuntu’s GCC, Intel compiler, MinGW. All shift in the sign bit. I guess Xcode’s GCC does the same. I know that the behavior is implementation specific, but it looks like that all major desktop/server compilers implement arithmetic shift. Are there any widely used compiler that doesn’t shift in the sign bit?Thank you.
Peter O.
c++ database otl soci
What are the advantages and disadvantages of the C++ database libraries OTL and SOCI? In particular, what differences are relevant for my project, whose database uses SQL Server 2008?I haven’t used either before, and during my project I don’t want to change the library.
SoapBox
c++ templates
I have a template class with an overloaded + operator. This is working fine when I am adding two ints or two doubles. How do I get it to add and int and a double and return the double?template <class T> class TemplateTest { private:T x;public:TemplateTest<T> operator+(const TemplateTest<T>& t1)const{return TemplateTest<T>(x + t1.x);} }in my main function i havevoid main() {TemplateTest intTt1 = TemplateTest<int>(2);TemplateTest intTt2 = TemplateTest<int>
Buddhika Chaturanga
c++ c++11
This question already has an answer here:C++ Const Usage Explanation9 answersI am a student,Learning C++ Concurrency Programming.I want to know how to access Functionality both Graphic Card chip and Sound Card chip through my C++ program.Is there another way to connect respective drivers and my application without using external libraries such as OpenGL,OpenAL etc.Can you briefly describe the solution by an example. Thank you.
ildjarn
c++ visual-studio-2010 visual-c++
This may be hard to explain. I have been developing a program for about a month now in MS VisC++ 2010 express. I have had no strange problems and was ready to build my project for the 100th time when suddenly, many of the .cpp files seemed to loose contact with the .h files. For instance, in the main function, objects that I had created and used weeks ago, suddenly got the red line under them and the syntax error “theClass is undefined”. This applies to iostream, so suddenly cout is undefine
Olcay Ertas
qt ubuntu arm cross-compiling
I am trying to compile Qt embedded for ARM. I have followed the instructions both here and here. I am using latest Angstrom toolchain and qt-embedded-linux-opensource-src-4.5.3 and I am using Ubuntu 10.10 x86.Here steps I past:Configured qws/linux-arm-g++/qmake.conf file for my toolchain. Here it’s content:# # qmake configuration for building with arm-linux-g++ #include(../../common/g++.conf) include(../../common/linux.conf) include(../../common/qws.conf)# modifications to g++.conf QMAKE_CC
iviv
c++ qt qml sample
My setup is Qt5.0.2 MinGW 32-bit. I am looking for { Qt5.0.2 / QML / QtQuick2.0 / C++ } code project examples (not Qt Quick 1.0) that have actual C++ classes or at least a main.cpp .I ran through the web, browsed all examples I could possibly find:http://qt-project.org/ website; github; stack overflow (if anyone had previously addressed this question); http://www.developer.nokia.com/Develop/Qt/Code_examples/ but they were either old (Qt Quick 1.0) or pure QML+ QtQuick 2.0 or did not comp
Rafe
python qt selection qtreeview selectionmodel
I am trying to restrict selection of a tree to a particular column. I am using delegates heavily to create custom per-item-per-column behaviors, editors, etc. I was hoping I could somehow do this from a delegate by blocking an event or something similar. The problem is, I think i would have to create an entirely custom solution that mimics extended selection. However, after a lot of searching and very few examples, it sounds like I want a custom QItemSelectionModel on my tree view. Is this assum
sudeepdino008
python qt pyqt pyqt4
import sys from PyQt4 import QtCore, QtGuiclass Class2(object):def __init__(self,parent):self.welcomeScreen(self)def welcomeScreen(self,parent):print ‘hello’self.centralwidget=QtGui.QWidget(parent)self.tabWidget=QtGui.QTabWidget(self.centralwidget)self.tabWidget.setGeometry(QtCore.QRect(0,0,661,511))self.tab=QtGui.QWidget()self.lineEdit=QtGui.QLineEdit(self.tab)self.tabWidget.addTab(self.tab,””)self.tabWidget.show()class Class1(QtGui.QMainWindow):def __init__(self):super(Class1, self).__init__()
goldfrapp04
c++ qt build preprocessor define
Just a Qt Gui Application with QDialog as the Base Class, the simplest type you can expect. I’ve programmed on Qt for several times but this is the first time I meet this problem… I’ve added minimal code to the program, and here’s the code in dialog.h (which is mostly automatically generated)#ifndef DIALOG_H #define DIALOG_H#include <QDialog> #include <QPixmap> #include “bmp.h”namespace Ui {class Dialog; }class Dialog : public QDialog {Q_OBJECTpublic:explicit Dialog(QWidget *parent
Lars
c++ qt
I have some kind of dilemma.I’m using:MSVS 2008 Qt 4.7.3 (with Qt VS Add-in 1.1.9)I wrote small Qt application, base on QMainWindow class, where also exists settings dialog (QDialog). Every works fine in GUI mode. After that I started to change my project to make it visible only in tray. Just comment in main.cpp show() method, like this:MainWindow w; //w.show();return app.exec();But from tray, I need to launch settings dialog, which is implemented in mainwindow.h/.cpp files. I added to tray menu
rubenvb
qt qimage
I am getting unexpected output from a piece of code that is simply accessing image coordinates, here’s a snippet:QImage image(imageFileNames[frameNumber]); QRgb qrgb(image.pixel(493,114)); QColor testCol(qrgb);Using the debugger to make sure I get the right image path I get something like ../seq/0001.png, which is as expected. However, testCol has the values of:[argb] alpha 65535 blue 28013 green 24415 pad 0 red 59367Instead of the expected value within the 255,255,255 range. Also, the value of
samprat
c++ qt qfile
Brief description: IN my Qt utility , I want that as soon as user hit the close button following things happens 1) A File Dialog box appear with save /cancel options and with default file name in it. 2) If the user has saved the file in different location on his computer , I should be able to write logs on that saved file.I have done the first part but I am clueless on how to retrieve the file name with full path when the user has already closed the dialog box.MY code for part 1 is giv
Laszlo Papp
c++ sql qt pyqt qtsql
After setting up a table model like this:from PyQt4.QtSql import * from PyQt4.QtCore import * from PyQt4.QtGui import * import sysdef createConnection(driverType, databaseName, hostName=None, userName=None, password=None):db = QSqlDatabase.addDatabase(driverType);db.setDatabaseName(databaseName)db.setHostName(hostName);db.setUserName(userName);db.setPassword(password)if (db.open() == False):QMessageBox.critical(None, “Database Error”, db.lastError().text())return Falsereturn dbif __name__ == ‘__
user2493039
c++ qt real-time
I am creating an app in Qt, similar to scribble (given in sample app). Purpose is to let user draw freehand and once finished, upload these drawing to net. As of now I am saving the drawing as PNG image every 5 seconds, so that the loss of data in an event of unexpected shut-down is minimum (I kept 5 sec to minimize write operations; Real real-time would be highly desirable). But the problem is, I am saving the entire page as an image every 5 seconds, where the new data added may be few pixels.
Jonathan Wakely
c++ mingw codeblocks glew
I need to build GLEW from source so I can use it with Mingw in Code::Blocks being Mingw doesn’t like to use the one’s they compile in VS. I’m using Cygwin and I download the source for GLEW here and unzip it. I then browse to the folder with Cygwin using cd. Then I runmake MakefileIt then gives me these errors. config/config.guess: line 6: $’\r’: command not found config/config.guess: line 8: $’\r’: command not found config/config.guess: line 26: $’\r’: command not found config/config.guess: lin
michj36
ubuntu codeblocks pkg-config sdl-2 sdl-image
i’ve installed SDL2 (with SDL2_image and SDL2_ttf as well) from sources – SDL2 from http://www.libsdl.org/hg.php , SDL2_image and SDL2_ttf did I find on http://archive.ubuntu.com/ . The project I’m working with (using CodeBlocks) builds successfully, but when i run it, I get error messages in XTerm:Failed loading png_set_longjmp_fn: /lib/x86_64-linux-gnu/libpng12.so.0: undefined symbol: _png_set_longjmp_fnThen I try to reinstall SDL2_image, but rebuilding it not with $ ./configure but with$ .
Theocharis K.
winapi gui command-line codeblocks
I have recently started a tutorial to learn how to code GUI using Windows API and I have come upon an unexpected question which I think is kind of silly. I am using Code::Blocks with OpenWatcom compiler as default and I have created a simple GUI program compiling and linking well. The problem is when I try to launch the program, even from the release version something like the command line shows up behind the window of my program, like I tried to run it through the compile & run option of th
Atul Kumar Verma
c ide double codeblocks
I am using Code::Blocks 12.11 on windows 64-bit platform for C/C++ codes. I recently came across an unexpected result for this program.#include <stdio.h>int main(){long double number;number = 1.1234567;printf(“%llf\n”,number);return 0;}It should print the output 1.1234567 but it gives -0.000000, I figured out that it always gives wrong values when i use long double. This code works fine on ideone http://ideone.com/Opu8cy , Please tell me is there any way to Fix this.
Sam Holder
c# asp.net-mvc-2 codeblocks
I’m developing a new ASP.NET MVC 2.0 application and wanting to use the new ASP.NET 4 encoding blocks.My View code contains <%: Model.ActivityName %> however Visual Studio is reporting: Unexpected tokenat the position of the : (colon). When I run the application I get the following compilation error:Compiler Error Message: CS1525: Invalid expression term ‘:’What am i missing?Cheers for any help/advice.
Johnny Bones
c codeblocks
I’m a beginner and I am having a problem with the code I’m writing .. I’m receiving the following error: “Unexpected unqualified-id before ‘{‘ token in line 9″Also, I don’t know how to set the output and make it shown so if you guys could really help me with that I would be grateful ..And just to let you know .. I’m using the “Code Blocks”#include<stdio.h> #include<conio.h>int read_temps(float temps[]); int hot_days(int numOfTemp, float temps[]); int printf_temps(int numOfTemp,float
feelfree
c++ linux codeblocks
The following codes can compile very well in VC10:#include <vector> #include <iostream> #include <math.h>#define _USE_MATH_DEFINES #include <math.h> #include <assert.h> #include <iostream> #include <vector> #include <utility> #include <functional> #include <numeric> #include <algorithm> #include <limits>template <typename T>class Coordinate{public:T x_; ///< x_coordinateT y_; ///< y_coordinate/*** Default cons
genpfault
c++ gcc sdl codeblocks quit
I am programming a game. Without fail, the program will cleanly close after about 10 seconds. I thought it was a problem with my state machine but when I change the GAME_CLOSED event to just restart the game, the game still closed. No errors are logged.I have no overarching timing routine that could even detect how much time had passed, much less through multiple states (right now you can pass through the splash and title screens or not, and regardless of what happens it always quits after the s
user3069863
mingw codeblocks argv dev-c++
I’m in trouble when trying to access from a CPP file the command line arguments. Using __argv used to work fine for years but now, I’m getting a different response when using Dev-CPP (ver. 5.5.3) and Code::Blocks (svn build rev 9248 patched to work with FORTRAN). Below I’ve pasted a 3 statements example and commented above the lines troubling me, while below the final brace I’ve added compile and link commands. What I stopping me from still using __argv ? #include <stdlib.h> #include <
Lienau
c++ mingw codeblocks
I’ve been trying to include winhttp.h and I get this error:Winhttp.h: No such file or directoryMingw doesn’t have it, how would I add it?
Web site is in building