我对我的代码进行了一些编辑,然后做了大约15"撤消"回到我上次编译成功的地方的操作,只是代替编译而得到了这个从未见过的错误:
expected unqualified-id before 'nullptr'
双击错误会将我带到qcompilerdetection.h
的以下部分,这是我从未知道的文件。我对代码的编辑怎么可能搞乱这个文件?或者这是真正问题的误导?我知道我已经出现错误,因为代码中的某个地方缺少一个支架...所以我检查了我在上次成功编译和这个编辑之间编辑的每一行代码。不幸的是,我是一个白痴并在关闭程序之前,重做所有内容以确定是否修复了它。所以现在我不知道要修改什么,而且如果不进一步破坏我的代码,我就会做太多的菜鸟做任何事情。
/*
* C++11 keywords and expressions
*/
#ifdef Q_COMPILER_NULLPTR
# define Q_NULLPTR nullptr
#else
# define Q_NULLPTR NULL
#endif
#ifdef Q_COMPILER_DEFAULT_MEMBERS
# define Q_DECL_EQ_DEFAULT = default
#else
# define Q_DECL_EQ_DEFAULT
#endif
#ifdef Q_COMPILER_DELETE_MEMBERS
# define Q_DECL_EQ_DELETE = delete
#else
# define Q_DECL_EQ_DELETE
#endif
具体来说:
# define Q_NULLPTR nullptr
^
如果知道的话,我正在使用Raspberry Pi 3在Qt5中设置QThread。之前从未见过像这样的问题,只有我实际编写的代码中的错误。这是我调试器派上用场的地方吗?我不知道如何在Qt Creator中使用它。
如果它有助于查看......这是我正在处理的代码。
press.cpp
中的
#include <QDebug>
#include <wiringPi.h>
#include "functions.h"
#include "press.h"
#define PUMP 21
#define SOLENOID_DWN 24
#define SOLENOID_UP 25
#define LIGHT_LEFT 26
#define LIGHT_RIGHT 27
#define LASER 28
#define ENCODER_A 0
#define ENCODER_B 2
#define PEDAL_RIGHT 12
#define PEDAL_LEFT 13
#define HOME 14
Press::Press()
{
}
void Press::programRun() {
qDebug() << "Hunting Position...";
qDebug() << positionTarget;
digitalWrite(PUMP,HIGH);
digitalWrite(SOLENOID_DWN,HIGH);
upFlag = 0;
while (pos > positionTarget){
if (stopFlag == 1){
emit stop();
qDebug() << "emit stopped";
return;
}
if (pausedFlag == 1){
if (digitalRead(PEDAL_LEFT) == LOW){
//Functions::programUnpause();
emit resume();
qDebug() << "emit resumed";
delay(100);
while (digitalRead(PEDAL_LEFT) == LOW){}
delay(100);
}
}
if (digitalRead(PEDAL_RIGHT) == LOW){
emit stop();
//Functions::programStop();
delay(100);
while (digitalRead(PEDAL_RIGHT) == LOW){}
delay(100);
}
if (digitalRead(PEDAL_LEFT) == LOW){
//Functions::programPause();
emit pause();
delay(100);
while (digitalRead(PEDAL_LEFT) == LOW){}
delay(100);
}
delayMicroseconds(30);
}
//Functions::solenoidOff();
//Functions::solenoidUp();
upFlag = 1;
//Functions::programPause();
emit pause();
while (digitalRead(HOME) == HIGH){
if (stopFlag == 1){
emit stop();
qDebug() << "emit stopped";
return;
}
if (pausedFlag == 1){
if (digitalRead(PEDAL_LEFT) == LOW){
//Functions::programUnpause();
emit resume();
qDebug() << "emit resumed";
delay(100);
while (digitalRead(PEDAL_LEFT) == LOW){}
delay(100);
}
}
if (digitalRead(PEDAL_RIGHT) == LOW){
emit stop();
//Functions::programStop();
delay(100);
while (digitalRead(PEDAL_RIGHT) == LOW){}
delay(100);
}
if (digitalRead(PEDAL_LEFT) == LOW){
//Functions::programPause();
emit pause();
qDebug() << "emit paused";
delay(100);
while (digitalRead(PEDAL_LEFT) == LOW){}
delay(100);
}
delayMicroseconds(30);
}
qDebug() << "FINISHED";
emit stop();
Functions::solenoidOff();
}
并在main.cpp
#include <QCursor>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QFile>
#include <QByteArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <QFuture>
#include <QThread>
#include <QtConcurrent>
#include <QObject>
#include <wiringPi.h>
#include <pthread.h>
#include "datahandler.h"
#include "functions.h"
#include "press.h"
#define PUMP 21
#define SOLENOID_DWN 24
#define SOLENOID_UP 25
#define LIGHT_LEFT 26
#define LIGHT_RIGHT 27
#define LASER 28
#define ENCODER_A 0
#define ENCODER_B 2
#define PEDAL_RIGHT 12
#define PEDAL_LEFT 13
#define HOME 14
QScopedPointer<Functions> myFunctions(new Functions);
QScopedPointer<DataHandler> myData(new DataHandler);
QThread* thread = new QThread;
Press* pressProgram = new Press();
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
app.setOverrideCursor( QCursor( Qt::BlankCursor ) ); //Hide the cursor
pressProgram->moveToThread(thread);
QObject::connect(thread, SIGNAL (started()), pressProgram, SLOT (programRun()));
QObject::connect(pressProgram, SIGNAL (stop()), thread, SLOT (quit()));
QObject::connect(pressProgram, SIGNAL (stop()), thread, SLOT (deleteLater()));
QObject::connect(pressProgram, SIGNAL (stop()), pressProgram, SLOT (deleteLater()));
//thread->start();
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("pressProgram",pressProgram);
engine.rootContext()->setContextProperty("myFunctions",myFunctions.data());
engine.rootContext()->setContextProperty("myData",myData.data());
engine.rootContext()->setContextProperty("noteProfileArray",noteProfileArray);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
答案 0 :(得分:0)
原来这种情况属于所有情况的99%:语法错误。
在我认为没有编辑的内容中发现了一行错误的代码,并且IDE没有将其挑出来,但需要修复。我怀疑,头文件错误是一个误导,我真的很感激评论:
&#34;编译某些.cpp
文件时,通常会出现头文件中的错误。&#34;
很高兴知道我的代码没有直接破坏编译器级别的文件,而是导致任何数量的奇怪背景事物出错,表现为看似根深蒂固的问题。
旁注:我认为我犯了这个错误是因为我编辑了多个.cpp文件而且必须忘记&#34;撤消&#34;其中之一。我希望有一种方法可以在Qt Creator项目中全局撤消操作。