Qt Creator warning: ‘auto’ changes meaning in C++11; please remove it

Just wrapped up section 3 of my Qt C++ beginner GUI course! Boy, this course is fun! I really appreciate the instructor taking the time to show 3 different ways to do things, and explaining why one might be more useful than others in different situations. I did run into a couple of errors though:

warning: ‘auto’ changes meaning in C++11; please remove it

And this one, too:

error: no matching function for call to ‘Widget::connect(QPushButton*&, void (QAbstractButton::*)(bool), Widget::Widget(QWidget*)::<lambda()>)’
});

Both of these are related, so I thought I’d bundle them together in this post. Apparently, GCC for Linux, while super smart, is so flexible that you can, of course, use different C++ standards, however, by default, it uses the OLDEST one. WHY?! So, in Qt creator, you have to tell it specifically to use the latest C++ standard, like so:

#-------------------------------------------------
#
# Project created by QtCreator 2018-06-22T09:40:37
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = section_3_18
TEMPLATE = app


SOURCES += main.cpp\
        widget.cpp

HEADERS  += widget.h

FORMS    += widget.ui

QMAKE_CXXFLAGS = -std=c++14
QMAKE_LFLAGS = -std=c++14

Those last two QMAKE lines are the ones I added. You can set them to any standard you like that is in your compiler, such as c++11, c++14, c++1z (well, on mine that is the 2017 standard, some newer ones may have c++17). Adding those two lines and saving the file will fix it.

The second error was caused because I had Qt4 and Qt5 installed. Obviously, you should use the newest one available to you. So, I had to click:

Tools->Options->Kits->Desktop

qt_3_17

And choose the latest Qt5 version, rather than the default of the lower Qt4 version. It took me a while of web browsing to figure this out, so hopefully this will save someone else some time!

Linux – keep it simple.

Advertisements

BLOX2: “Wakey, Wakey, Mouse!”

sleep2wake

That quote is from one of my son’s favorite books, “Max the Brave”!

Another update to the BLOX2 (BLU Life One X2) kernel, I just added Sweep2Wake and DoubleTap2Wake! You can check out the commit on GitLab, but my phone’s screen and proximity sensor are smashed, so I’m not sure it all works properly. It’s all part of my video series for modifying 64 bit kernels, which you can check out on my YouTube channel: https://www.youtube.com/channel/UCnGqG_jyyXmTzdamBpKfeHA

Linux – keep it simple.

Building picoEngine, a UCI Compatible Chess Engine

When I started programming, one of my early ideas was to build a chess engine. What sounds more sophisticated for a programmer, than building something like that? It just sounds smart!

Thus entered the “Beginner Engine” which I built for Android using a YouTube tutorial by Logic Crazy. It was great to have someone who programmed in Java explaining every step of making a playable engine. Unfortunately, it had some serious flaws for use on Android. None of which was Logic Crazy’s fault, he was showing the basics of building an engine. But it couldn’t castle, and bogged down my phone every time I used it.

After learning the ropes, I decided to build the “JustChess Engine”. It no longer bogged down the system, and despite being relatively stupid, it is quite playable (except for a pesky en passant bug that I still need to fix). The problem with using the JustChess Engine is that it was written by me for my application, so it does not respond to regular engine commands, like those from the UCI, or the Universal Chess Interface. Instead it only responds to my commands that I programmed it with.

picoEngine_1

Here you can see my new engine, picoEngine, talking to Arena Chess!

Hence, I’ve decided to build a UCI compatible chess engine, so I can learn how to interface with GUI’s through UCI. Thus, I’ve started a C++ project called “picoEngine”, which literally means very small engine. You can check out the first commit on my GitLab, and here is my first bit of working code:

/* Copyright 2018 by AlaskaLinuxUser (https://thealaskalinuxuser.wordpress.com)
*
* Licensed under the Apache License, Version 2.0 (the “License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an “AS IS” BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <iostream>
using namespace std;

string engineName = “picoEngine A01”;
string inputString;

void inputUCI();
void inputSetOption(string setString);
void inputIsReady();
void inputUCINewGame();
void inputPosition(string posString);
void inputGo();
void inputQuit();
void inputPrint();
bool runProgram = true;

int main()
{
cout << “Waiting….”;

while(runProgram) {
getline(cin, inputString);

if (inputString == “uci”)
{
inputUCI();
}
else if (inputString.rfind(“setoption”, 0) == 0)
{
inputSetOption(inputString);
}
else if (inputString.rfind(“isready”, 0) == 0)
{
inputIsReady();
}
else if (inputString.rfind(“ucinewgame”, 0) == 0)
{
inputUCINewGame();
}
else if (inputString.rfind(“position”, 0) == 0)
{
inputPosition(inputString);
}
else if (inputString.rfind(“go”, 0) == 0)
{
inputGo();
}
else if (inputString.rfind(“quit”, 0) == 0)
{
inputQuit();
}
else if (inputString.rfind(“print”, 0) == 0)
{
inputPrint();
}
}
return 0;
}

void inputUCI()
{
cout << “id name ” << engineName << endl;
cout << “id author Alaskalinuxuser” << endl;
cout << “Apache 2.0 License.” << endl;
cout << “https://thealaskalinuxuser.wordpress.com&#8221; << endl;
// Options can go in here
cout << “option name Style type combo default Normal var Random var Normal” << endl;
// End of Options
cout << “uciok” << endl;
}
void inputSetOption(string setString)
{
cout << “Setting Options….” << endl;
// Set your options like: setoption name Hash value 32
cout << “Options set.” << endl;
}
void inputIsReady()
{
// Are we ready for input?
// Do any initialization first.
cout << “readyok” << endl;
}
void inputUCINewGame()
{
cout << “Creating New Game….” << endl;
}
void inputPosition(string posString)
{
cout << “Accepting Position….” << endl;
}
void inputGo()
{
cout << “Going….” << endl;
}
void inputQuit()
{
cout << “Quiting….” << endl;
runProgram = false;
}
void inputPrint()
{
cout << “Printing Board….” << endl;
}

I was even able to load it into Arena Chess and talk to it through the interface. Obviously it ran out of time because it can’t actually make a move, but it did respond to standard uci commands, which is great!

Linux – keep it simple.

Qt 5 and C++ meet in a graphical user interface!

Section 2 is complete of the “Beginning Qt 5 C++ GUI Development” course! This course is great! I’m really learning a lot from the instructor. Section 2 was sort of a C++ primer, for those who were not familiar with it. As you know, if you’ve been following along here, I already learned C++ in another course. However, in this “primer” of C++, I gained a much deeper understanding of what exactly classes are, how to properly use constructors and all sorts of great stuff!

qt_gui

Check out my “Guess the number” game!

I’m not sure if I think the course is so great because I already know a little about C++, or if it just is that informative, but it seems to me that it moves at a great pace for beginners like myself.

You can check out my completed game, although it’s not much to see yet. The object is to guess the number which is between 1 and 10. You’ll have to import it into Qt-Creator and then compile it. I haven’t started making executables yet.

As an aside, if you are familiar with Android Studio, Qt-Creator is somewhat similar in feel and use. I like how you can right click on an object and add code directly to your cpp files, which is really handy!

Linux – keep it simple.

New Course! Beginning Qt 5 C++ GUI Development : The Fundamentals

I’ve just completed the first of 10 sections in a new course I am taking on Udemy. The course is called Beginning Qt 5 C++ GUI Development : The Fundamentals. As you know, if you’ve been following along, I started learning C++ using a course on Udemy that particularly focuses on graphics through SFML. It was a lot of fun learning to program in C++ while making a few games.

While making those games was really neat, I realized that I now need a way to make applications that aren’t games. I suppose you could use SFML for that, but it seems a bit overkill to make your own buttons for everything, when they have great programs for that already. Programs like Qt and Qt-Creator.

Licensed under the GPL-2 and GPL-3, Qt is open source, which is a big plus for me. Qt is also written in C++, which I am currently learning, so that is the primary reason that I want to use it. And did I mention that it’s cross platform? The IDE is Qt-Creator, which is licensed under the LGPL, a copyleft license, which makes it free for me to use and open sourced for those who wish to contribute, which is great!

qt_2

I’ve only just started working with it, but I really like the user interface of Qt-Creator thus far. The course itself has a huge plus for me, in that the author/instructor also supports Linux users, even providing a video tutorial for installing the application and how to deal with a few possible errors that may pop up if the right dependencies are not installed. That is really rare these days!

If you want to follow along, be sure to check out my first Qt commit!

Linux – keep it simple.

BlueFruit Project: Fixed Erratic Crank Behavior

Another problem that I have run into while working with this Bluetooth auto start is an erratic crank behavior. Per the code, it should not start the crank circuit if the engine is already running. However, on 2 occasions, it happened anyways. I was not plugged in with a laptop at the time, so I don’t know what the issue was, and I can’t go back in time to hook up and review the logs.

IMG_20180723_071854

Notice that the white auto start box is gone. I’ve relocated it to the glove box.

I plugged in the laptop and went through the functions and processes again. The only thing I can come up with is if the “runbool” flag did not get set somehow, and it didn’t believe that the truck was running. So, I decided to add yet another layer of safety.

Here is what I came up with:

 

@@ -174,16 +174,16 @@ void loop(void) {


if (startTimer == 0 && startAttempts > 0) {

if (voltVoltage >= 0.9) {

// Turn everything off because it is running.

// Turn everything to a run state because it is running.

// I had to add this as a safety. Once or twice this cranked when it shouldn’t have,

// before this code existed. Now it can’t crank without checking first!

digitalWrite(16, LOW);

digitalWrite(15, LOW);

digitalWrite(7, HIGH);

digitalWrite(11, HIGH);

digitalWrite(7, LOW);

digitalWrite(11, LOW);

crankTimer = -1;

startTimer = -1;

runTimer = -1;

runTimer = 600; // We are here because something messed up, but set the clock to 10 minutes.

startAttempts = -1;

Serial.println(” Already running! “);

} else {
… …
@@ -194,7 +194,7 @@ void loop(void) {

Serial.println (” crankTimer ON “);

}

} else if (startTimer == 0 && startAttempts == 0) {

// Turn everything off from to many attempts.

// Turn everything off from too many attempts.

digitalWrite(16, LOW);

digitalWrite(15, LOW);

digitalWrite(7, HIGH);
… …
@@ -220,7 +220,7 @@ void loop(void) {

Essentially, I am just running one last voltage check right before turning on the cranking power. If the voltage is above 13 volts, the engine must be running, so I don’t want to crank.

Using voltage this way is somewhat risky, because it is possible that the charging circuit of the car is not working, and voltage has depleted, causing the cranking circuit to engage the already running motor that just isn’t charging the battery. That is why I would like to pursue some sort of tachometer sensor input.

Until then, I think this will keep me (relatively) safe, as long as the vehicle charging system works properly.

Linux – keep it simple.

Text field types to capitalize sentences…

device-2018-09-10-130014

I recently received a comment from a Just Notes user about how much they loved the simplicity of the notes app. However, they also pointed out that the text field that you type into doesn’t automatically capitalize sentences or names, and somewhat lacks a bit in terms of use.

He was right.

I typically use this for typing grocery lists, and things that don’t turn out to be complete sentences. So I noticed, but it didn’t really matter to me. I realize that others may use it differently, so I wanted to fix this.

So I did.

You can check out the commit here, where I updated to the target api of 26 (per Google’s requirements to be listed on the Play Store now – *sigh*) and changed the text field type. Here is the only thing that actually changed in my app, from this:

android:inputType=”textMultiLine”

to this:

android:inputType=”textCapSentences|textAutoCorrect|textAutoComplete|textMultiLine” />

And that’s it. That makes it work with auto correct, auto complete, and to capitalize sentences!

Linux – keep it simple.

BLOX2: Voltage Control for the CPU!

cpuvolt

Another update to the BLOX2 (BLU Life One X2) kernel, I just added the ability to adjust the voltage of the CPU on the fly! You can check out the commit on GitLab, but it currently only controls the voltage on the “big” 4 CPU’s, not on the “small” 4 CPU’s. It’s all part of my video series for modifying 64 bit kernels, which you can check out on my YouTube channel: https://www.youtube.com/channel/UCnGqG_jyyXmTzdamBpKfeHA

Linux – keep it simple.

BlueFruit Project: Low voltage safety

IMG_20180720_100112Having tested out the Bluetooth auto start for a little while through regular use, I came to an interesting conundrum. What should the auto start do if the voltage is too low? I “hemmed and hawed” about this for a while and here are my thoughts:

  • If the vehicle is already running, should we shut it off when the voltage gets to low? No, because turning it off will not help the driver in any way (except to alert them to an issue) but they may want it to stay on.
  • If the vehicle has not started yet, should it attempt at all? Yes, we should make at least one start attempt, so that the alternator can kick in and charge the battery.
  • If the vehicle failed to start, should we try again with a low battery? No, I suppose they should manually start the vehicle to ensure cranking goes properly.

With those three thoughts in mind, here is what I came up with:

if (crankTimer == 0) {
digitalWrite(15, LOW);
digitalWrite(11, HIGH);
if (runBool) {

crankTimer = -1;

startTimer = -1;

startAttempts = -1;

runTimer = 600; // 600 seconds = 10 minutes of run time before shutdown.

Serial.println (” crankTimer OFF, runTimer started. “);

} else {

crankTimer = -1;

startTimer = 5; // To start process again.

runTimer = -1;


startAttempts = startAttempts -1;

if (voltVoltage <= 0.5) {

// Voltage is too low to try again!

startTimer = -1;

Serial.println (” Voltage LOW! “);

} else {

startTimer = 5; // To start process again.

}

runTimer = 600; // 600 seconds = 10 minutes of run time before shutdown.

Serial.println (” Not running, try again… “); Serial.println(startAttempts);

}

So it will attempt one start, but not multiple starts. What do you think? Is that reasonable?

Linux – keep it simple.

Segmentation fault (core dumped)!

One of the most frustrating problems I’ve run in to date on my Water Drum game! Take a look at the output in the terminal:

alaskalinuxuser@alaskalinuxuser-OptiPlex-7010:~/Documents/c++/sfml_projects/sfml_water_drumming$ ./build.sh
DrumGame.cpp: In function ‘int main()’:
DrumGame.cpp:428:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (roundNum == demoMode.length()) {
^
DrumGame.cpp:432:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
} else if (roundNum < demoMode.length()) {
^
DrumGame.cpp:506:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (currentDemo == demoMode.length()) {
^
./build.sh: line 14: 3281 Segmentation fault (core dumped) ./DrumGame-app
type ./DrumGame-app to launch

A segmentation fault! But why?! It doesn’t really mention it here, so I tried to pull an strace on the program. Amongst pages and pages of gibbly-gook, there was this little gem about the exitButton being out of range.

DOH! I can be really, really, really dumb sometimes!

Here was my code:

window.draw(exitButton[numExitButtons].getSprite());

That should have been written as:

window.draw(exitButton[0].getSprite());

You see, there is only 1 exit button, so the numExitButtons variable was set to just 1. However, in an array (the []) the first (and only) exitButton starts with numeral zero! Boy, I can be a real dunce sometimes! All that time spent working on the issue that was a coder induced numerical error!

2018-06-12-124140_1280x1024_scrot

But, praise God, the DrumGame-app, Water Drumming! is complete! You can check the latest commits on GitLab, and download the source code as well! Be sure, once you extract it, to run the ./build.sh script. This game does require libsfml. If you try it out, you should drop a line to say what you think of it!

Linux – keep it simple.