Transmitting an exe file via network in Qt - qt

I am trying to create a Remote compiling system in Qt. What I am trying to do is to get the C/C++ source from the client and calling the locally available GCC via QProcess on the server, create the exe file and then transmit the exe back to the client. Simple right?
The exe file is being generated perfectly but Qt is just not able to read the file into an array to transmit it.
My Code is:
QByteArray arr;
qDebug() << "To Client: exe";
QFile f("compiled.exe");
qDebug() << f.exists(); //output = false
QString path = QDir::toNativeSeparators(QFileInfo(f).absoluteFilePath());
qDebug() << path; //perfect path is coming
qDebug() << f.open(QIODevice::ReadOnly); //output = flase
arr = f.readAll(); // size of arr is 0
f1.close();
client->write(arr); //zero bytes written
Although the exe file is very much present, I am getting such outputs. I tried with other files in the same directory, it works absolutely perfectly. Only exe files wont work.
I am using Qt 4.8.1 32 bit on Windows using MSVC v16.00.40219.10 as the compiler.
Thanks in advance!!

No need to speculate, there is a description of error codes when using QFile::open().
Btw
qDebug() << f.exists(); //output = false
It seems compiled.exe is not in the process working directory, neither nor in any direcotry in path. Provide the complete path...

Related

qDebug()<<qstring no longer compiling

I have built a QWidgets application in Qt 5.3.1 and in some places have used
qDebug() << msg;
where msg is a QString.
I had had this compiling and running for a few years, but tonight I decided to recompile it and I got the message:
D:\devt\myapp\extcoder.cpp:29: error: no matching function for call to 'QMessageLogger::debug()'
qDebug()<<msg;
^
In fact I got a similar problem in another app I wrote the other day, and by experimenting I thought I had fixed it by replacing such calls by qDebug(msg).
But it looks as if some kind of software rot is setting in!
Any ideas? Of course the file starts with
#include <QDebug>
To test this problem I built a barebones QWidgets application (of a QMainWindow kind), and the only code I wrote, was (apart from the #include)
qDebug()<<"Hello world";
in the MainWindow constructor. I get exactly the same compilation error.
Reinstallation of Qt made qDebug()<<s work again.
It was indeed a kind of "software rot": I reinstalled qt 5.3.1 after making a copy of the original so I could compare the new with the old.
Using Winmerge I was able to uncover the error:
I dont know exactly how it happened but the file qlogging.h got corrupted.
Here's what happened: at lines 118 and 120 the declarations of two versions of debug got rewritten to NBIS_debug.
Now I have worked trying to port free software from the NBIS. At some stage I must have renamed a debug function from debug to NBIS_debug, and this modification must have been propagated all the way to qlogging.h.
QDebug &QDebug::operator<<(const QString &s) is supported in Qt.
Output example:
QString s;
s = "a";
qDebug().noquote() << s; // prints: a
qDebug() << s; // prints: "a"
Your Qt environment must be broken. Please, check your environment and re-install Qt if needed.
I had to reinstall Ubuntu and Qt. The reinstall only Qt did not help.

QtCreator: qDebug Messages Not Shown

I am currently using QT Creator 3.2.1 with Qt 5.3.2 (as required by my current project) on Windows 7 (64 bits, Ultimate). I am currently working on a GUI project
I am unable to see any qDebug messages in the Application Output window despite already done the following:
Having the appropriate QDebug code
Building the project in Debug mode
Using "CONFIG += openssl-linked" "CONFIG += console" as additional arguments for building the project
Not defining QT_NO_DEBUG_OUTPUT at all
Confirming that I have a debugger (GDB from MinGW 4.8.2 32 bit installed during installing QtCreator)
May I know what else should I try? Thanks!
This did it for me on Arch Linux
Qt creator > Tools > Options > Kits, select your kit, find Environment, click change and add:
QT_ASSUME_STDERR_HAS_CONSOLE=1
Now the Message can be printed in the Application Output
with something like that:
qDebug() << "User clicked on the button!";
And than you should see something in the program like so:
I don't get any debug messages supposed to be printed out by
qDebug() in Qt Creator? What could be the reason for that?
It is common to redefine the standard Qt debug output in Qt apps via the custom log message handler but we can still take care of making debug messages to reach the debug console:
// example for custom message handler
void customLogHandler(QtMsgType type, const QMessageLogContext& context,
const QString& msg)
{
// send the data to log file via the other thread
emit writeToFile(type, context, msg);
// now output to debugger console
#ifdef Q_OS_WIN
OutputDebugString(text.toStdWString().c_str());
#else
std::cerr << text.toStdString() << std::endl;
#endif
}
void main()
{
// custom handler start
qInstallMessageHandler(&customLogHandler);
// other app initializations
}

"Failed to make context current." on a computer without Qt

So I have been trying to develop a Qt application and run it on another Windows 8.1 machine which doesn't have Qt installed.
On my first computer, I used Visual Studio 2013 to develop my application and compiled it in release mode with the Multi-threaded DLL flag.
This produces a .exe file. In the same folder, I have:
accessible/ platform/
assimp.dll kernel32.dll
icudt52.dll icuin.dll
icuuc52.dll opengl32.dll
libEGL.dll libGLESv2.dll
Qt5Core.dll Qt5Gui.dll
Qt5OpenGL.dll Qt5Widgets.dll
msvcp110.dll msvcr110.dll
msvcp120.dll msvcr120.dll
I copied the Qt DLLs from C:/Qt32bits/5.3/msvc2013_opengl/. Except for libEGL.dll and libGLESv2.dll that I got from QtCreator as I couldn't find them in the previous folder. However, this shouldn't be a problem as I am compiling with msvc (not mingw), right?
In my code, at the very beginning I have:
QApplication app(argc, argv);
QGLFormat format;
format.setProfile(QGLFormat::CoreProfile);
format.setVersion(4, 0);
QGLFormat::setDefaultFormat(format);
/*And then later*/
cout << "Creating Window" << endl;
GLWidget *widget = new GLWidget(i); //i is the id of the widget
cout << "Widget created" << endl;
widget->makeCurrent();
cout << "Context current" << endl;
GLWidget derives from QGLWidget and in the constructor, I just set its ID attribute to i.
On my machine, everything works fine. But when I run my executable file on the second machine, I get the output:
"Creating Window"
"Failed to make context current."
"Widget created"
"Context current"
And then it crashes (MyApp.exe has stopped working)... What is weird is that "Failed to make context current" (which I believe was produced by makeCurrent()) comes before "Widget created"...
Any idea of what's wrong and how I could debug this?
Thank you very much for your time and help!
In the end it was a mix of problems:
The opengl32.dll that I was using seemed to be for 64 bits according to dependency walker (What's weird is that I took it from C:/System32/). I downloaded a new one for 32 bits and it worked fine. Thank you Sebastian Lange.
The second problem probably comes from the second machine's graphic card/OpenGL. I've tried on a third computer and now it works fine. Thank you vahancho.
Hope this can help future coders!

QFile does not create file on mac

I use this code (this is qt sample)
QFile file("out.txt");
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file);
out << "The magic number is: " << 49 << "\n";
I cant find file "out.txt" on mac. How to fix it?
Several Problems here :
Firstly you are not checking what is the return value of file.open().
Only if true will it actually create the file.
Also relative path so the file will be created at the application working directory when you call the open() method.
Also you will need write permission for the user in the directory for the file to be created.
You can check error stream for any errors that it will throw.
The file is writing to your apps package contents sitting next to the executable..
yourApp/Contents/MacOS/out.txt
I don't know how to get a file to write outside of the package contents though..
On the line:
QFile file("out.txt");
You need to specify all the root on mac!!
You should check your home directory. It should be there.

How can I see qDebug messages while debugging in QtCreator

I'm making the transition from Eclipse CDT (with Qt integration plugin) to QtCreator 2.0 but there is still one thing that bother me with QtCreator :
When I debug in QtCreator, I don't see my qDebug messages inside the Application output tab until I stop the application I'm debugging... Then they are all displayed at once which is not very useful.
With Eclipse, I don't have this problem : the qDebug messages are displayed correctly when encountered while stepping through the source code.
I'm using both Eclipse CDT and Qt Creator under Windows. I didn't try under Linux (which is not an option right now).
While not a complete answer, you can install DebugView (If you're on an XP machine) to view the qDebug output while you try to figure this out.
Another solution might be considered a hack, but works quite nicely, is to simply hijack debug messages yourself:
#include <QtCore/QCoreApplication>
#include <QDebug>
#include <iostream>
void msgHandler( QtMsgType type, const char* msg )
{
const char symbols[] = { 'I', 'E', '!', 'X' };
QString output = QString("[%1] %2").arg( symbols[type] ).arg( msg );
std::cerr << output.toStdString() << std::endl;
if( type == QtFatalMsg ) abort();
}
int main(int argc, char *argv[])
{
qInstallMsgHandler( msgHandler );
QCoreApplication a(argc, argv);
qDebug() << "Hello world.";
qWarning() << "Uh, oh...";
qCritical() << "Oh, noes!";
qFatal( "AAAAAAAAAH!" );
return a.exec();
}
Which would output:
[I] Hello world.
[E] Uh, oh...
[!] Oh, noes!
[X] AAAAAAAAAH!
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
This is actually a modification of some code that I use myself to send qDebug, qWarning, etc., to a log file.
You don't have to close the application to see qDebug() messages.
There is a tab named 3 - Application output at the very bottom of the Qt Creator. Clicking that window will show you the Application output window at the bottom of Qt Creator.
That particular window will display the qDebug() messages as soon as they get called while the application is still running.
Hope it helps.
Edit:
I am not sure whether this is an answer but it might be a good valid cause.
From qDebug() documentation,
The Qt implementation of these
functions prints the text to the
stderr output under Unix/X11 and Mac
OS X. With Windows, if it is a console
application, the text is sent to
console; otherwise, it is sent to the
debugger.
Now Qt Creator doesn't have it's own debugger attached to it.
From Qt Creator documentation, we have to manually install the debugger. Since you are using Windows, you need to install Debugging tools for Windows manually.. More documentation can be found here...
Though am not used to Eclipse CDT, I assume there might be a Debugger attached to it and hence it displays the Debugging output correctly..
Since there isn't a Debugger attached to the Qt Creator, it might be behaving strangely..
Just give it a try..
To add to the above answers..
Always make sure to build in debug mode and not in release mode..
As qDebug() , only works with the debug build.
This was the silly mistake i made, before my search for the led me here, and i wanted to add this fine but important point, to the list of other answers.
Have you tried to add the following line to your .pro?
OUTPUT += Console
Then you can output on std::cout.
Let me tell you something:
Once I have developed a c++ console application on linux. During running the application it was reading a file and starting to process some logic by printing out some status messages. When I run that application the output was OK. So for convenient debugging I have decided to run the application like this:
./a.out |& tee log
This command redirects standard output (may be also standard error I don't remember) into a file named "log". So when I run with this option I saw that it writes in the log file exactly the same as in std out only there are some displacements like this:
in std out - desired output
A
operation 1 success
B
operation 2 success
C
operation 3 success
D
operation 4 success
in the log file - output with displacement (this is not correct)
A
B
C
D
operation 1 success
operation 2 success
operation 3 success
operation 4 success
I guess your problem is this kind of one... I have taken a look at QDebug and have not seen any function that frees the buffer (something like operation called flush). So I recommend you to not waist your time on this kind of small issue (I also consider that Qt Creator 2.0 is release as a beta version and it may appear a bug) and use one of the following:
qFatal()
qCritical()
qWarning()
QMessageBox
I personally use QMessageBox::about in order to debug as you can stop the screan and read the value in a very usefull places that with debugger you can't (I mean you can but you can't see the current state of you GUI application as debugger have taken the control).
Hope helps.
This is a workaround, but you could probably install your own message handler. Take a look at qInstallMsgHandler in the documentation if you have not done so already.
I have a similar issue on Ubuntu 9.10 with Qt Creator 2.0 and Qt 4.7.0, though I don't see stdout output until the application is closed. It is as if the buffer isn't flushed.
Printing to stderr shows the output in the Application output window immediately though.
fprintf(stderr, "Test1 \n"); // Prints immediately
fprintf(stderr, "Test2 \n\r"); // Prints immediately
fprintf(stdout, "Test3 \n"); // Delayed until app termination
fprintf(stdout, "Test4 \n\r"); // Delayed until app termination
qDebug() << "Test6 \n\r"; // Does not print at all
None of these answers were right for me (Arch linux user). Rather than try to explain my troubles, here is a .pro file that worked. I'm not using the QT thread loop, purely just a simple main() that does stuff and exists. I'm using cout for my output:
QT += core
QT -= gui
CONFIG += c++14
TARGET = evo
#CONFIG += console
CONFIG -= app_bundle
#CONFIG += qt
#OUTPUT += console
TEMPLATE = app
SOURCES += main.cpp \
individual.cpp \
node.cpp \
tree.cpp
HEADERS += \
individual.h \
node.h \
tree.h
If Anyone is still looking for an answer, this is what I did:
In Debug tab go to build
under build select debug not release or profile
While running your application click the Application Output tab
Then you will see all your debugs message if you used a "qDebug()" macro.
my 2 cents contrib, in your main, just before a.exec :
qputenv("QT_ASSUME_STDERR_HAS_CONSOLE", "1");

Resources