aggregate ‘QSqlQuery testQuery’ has incomplete type and cannot be defined - sql

I'm sure this must be something simple, but I can't quite work out what's up here...
I'm trying to create a QSqlQuery, and the compiler is giving me this:
error: aggregate ‘QSqlQuery testQuery’ has incomplete type and cannot be defined
This code is in my mainWindow class:
void MainWindow::on_toolButton_clicked()
{
QString filename;
filename = QFileDialog::getSaveFileName(this, tr("Save to SQL Database"),
"~/temp",
tr("Files (*.fdb)"));
QSqlDatabase testDatabase = QSqlDatabase::addDatabase("QSQLITE");
testDatabase.setDatabaseName(filename);
//this line won't compile:
QSqlQuery testQuery;
testDatabase.close();
QSqlDatabase::removeDatabase(QSqlDatabase::database().connectionName());
}
Can anyone see what I'm missing here?

The error message indicates that the type SqlQuery is not completely defined. QSqlQuery is defined in
#include <QSqlQuery>
Include that and things should compile ok.

Related

SystemC ERROR: type name requires a specifier or qualifier

I am trying to write synthesizable SystemC code.
My code:
struct test:sc_module{
sc_in<sc_lv<4>> inp;
sc_out<sc_lv<4>> outp;
void run(){
sc_lv<4> temp = inp.read();
outp.write(temp);
}
SC_CTOR(test){
SC_METHOD(run);
sensitive << inp;
}
};
I am able to simulate the code, but when I run synthesis, Vivado HLS v.2019 throws the following errors. Can someone please help me understand how to fix this error?
ERROR: [HLS 200-70] Compilation errors found: In file included from test2/test.cpp:1:
test2/test.cpp:4:18: error: use of undeclared identifier 'inp'
sc_in<sc_lv<4>> inp;
^
test2/test.cpp:4:21: error: type name requires a specifier or qualifier
sc_in<sc_lv<4>> inp;
^
test2/test.cpp:4:21: warning: declaration does not declare anything [-Wmissing-declarations]
sc_in<sc_lv<4>> inp;
When I add spaces between the angular brackets (as below), it does not throw an error, and synthesis runs successfully.
sc_in< sc_lv<4> > inp;
sc_out< sc_lv<4> > outp;

no suitable user-defined conversion from System::String ^ to System::String exists

I'm relatively inexperienced with C++ and I'm currently creating a simple Windows Forms project. The following code is providing a strange error that I just can't wrap my head around.
if (folderBrowserDialog1->ShowDialog() == ::DialogResult::OK) {
String filepath = folderBrowserDialog1->SelectedPath;
for (auto& p : std::filesystem::directory_iterator(filepath)) {
// read files from filepath
}
}
The error, "no suitable user-defined conversion from System::String ^ to System::String exists" is referring to the folderBrowserDialog1->SelectedPath line. Despite the docs I've checked stating that SelectedPath is a string, apparently it's not the same type of string as C++ is expecting? I assume I need to do some kind of conversion but I'm at a total loss as to how I should do that as I really assumed that SelectedPath would be a regular String.

Managed C++, Object reference not set to an instance of an object

I've run into this problem before, but never in a situation like this. I'm completely confused. As the question states, I'm getting the runtime error "Object reference not set to an instance of an object." Using the debugger tools, I think I've pinpointed the problem to this line:
dataFileLocation = path;
The entire function is here:
void DATReader::SetPath(String^ path)
{
if(!File::Exists(path))
{
MessageBox::Show( "DATReader (missing dat file: \n"+path+"\n )", "Error", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
return;
}
dataFileLocation = path;
}
dataFileLocation is declared here, but nothing is assigned to it:
ref class DATReader
{
private:
System::String^ dataFileLocation;
// ...
}
Now I know the reason I'm getting the error is because dataFileLocation is assigned to nothing. But I'm having problems assigning it. When I add = 0; to it, it won't build because its a ref class. When I try to assigned it to = 0; in the constructor, it yells at me for trying to convert it from a System::String^ to an int. If I assign it to a = gcnew String(""); it builds, but throws the same runtime exception.
I don't get it, am I reading the debugger wrong, and this isn't the source of the problem at all? I've just started to use managed code recently, so I'm confused :\
You may want to check and make sure your DATReader object isn't null as well It may be throwing the exception at your DATReader.SetPath() call.
This is a nicety in C# that's missing in C++/CLI. C# generates code that ensures this can never be null. Easily seen in the debugger by setting a breakpoint on the method and inspecting "this". Here's an example program that reproduces the exception:
#include "stdafx.h"
using namespace System;
ref class Example {
String^ dataFileLocation;
public:
void SetPath(String^ path) {
dataFileLocation = path; // Set breakpoint here and inspect "this"
}
};
int main(array<System::String ^> ^args)
{
Example^ obj /* = gcnew Example */;
obj->SetPath("foo");
return 0;
}
Remove the /* */ comments to fix. Fix your code by looking at the call stack to find the method that forgot to instantiate the object.
Managed C++ uses nullptr for null references. So you can check:
if (path == nullptr) { ... }
or use:
if (!String::IsNullOrEmpty(path))

Mapping IOKit IOReturn error code to String

When I get error 0x10, I want to be able to make sense of that error code. Looking up IOReturn.h and mach/error.h is not particularly convenient. I was lost when I got 0x22 error code. This is really silly question but is there a function like error2String which can map IOReturn error code to String that describes the error ?
You can use the mach_error_string standard foundation function to do this.
Eg. in Swift:
func krToString (_ kr: kern_return_t) -> String {
if let cStr = mach_error_string(kr) {
return String (cString: cStr)
} else {
return "Unknown kernel error \(kr)"
}
}
Code running in the kernel can use IOService::stringFromReturn(...)

vtable error. "vtable for ETRun", referenced from:

I have an object called Run. I can instantiate in header of a class. But, when i try to do the same .cpp file the above error was popped out.
vtable error. "vtable for Run",
referenced from:
__ZTV5Run$non_lazy_ptr in Para.o
string Para::name()
{
Run* newRun = new Run;
return mName;
}
how can i get out of this error...
This probably happens because Run is a derived class, and it has a declaration of some virtual function but this function is not implemented.
Try to check whether your problem is this case.