 |
Forums |
Admin Discussion Forums: help Start New Thread
By: Janis-marie Newton
RE: Connecting a QByteArray to a QString [ reply ] 2011-03-16 03:56
|
Curtis,
I was reading the documentation for qt4-qtruby:
- Use underscore naming for method names instead of camel case if you prefer. Any underscores in method names are removed, and the following character is capitalised. For example, you can use either of these two forms to call the same method:
create_standard_status_bar_action()
createStandardStatusBarAction()
Thanks for the magic ;-)
|
By: Curtis Cooley
RE: Connecting a QByteArray to a QString [ reply ] 2011-03-15 17:50
|
Thanks for sticking with me. More typos on my part. @logs.text= is supposed to say @filter.text.
QProcess::readAllStandardOutput -> http://doc.qt.nokia.com/4.7-snapshot/qprocess.html#readAllStandardOutput
My current attempt at just using a thread is stalled since the thread will not run:
require 'Qt4'
require 'rubygems'
require 'net/ssh'
class LogChop < Qt::Widget
signals "has_data(QString)"
def initialize(parent = nil)
super(parent)
@filter = Qt::TextEdit.new(self)
end
def do_tail(session, file)
session.open_channel do |channel|
channel.on_data do |ch, data|
emit has_data(data)
end
channel.exec "tail -f #{file}"
end
end
def has_data(the_data)
@filter.text = the_data
end
end
root = Qt::Application.new(ARGV)
chop = LogChop.new
thread = Thread.new {
Net::SSH.start('server', 'user', :password => '********') do |session|
chop.do_tail session, "server.log"
end
}
thread.abort_on_exception=true
chop.show
root.exec
calling thread.status returns 'sleeping'
|
By: Janis-marie Newton
RE: Connecting a QByteArray to a QString [ reply ] 2011-03-15 15:55
|
I can't find the method:
read_all_standard_onput for QProcess. Are you leaving out other code?
> @logs.text= expects ... to say @logs.text="Hello World!"...
I dont see a an attribute / method text / text= for Qprocess (ie @logs).
when I run your code i get method missing right at:
puts @logs.read_all_standard_output
because, As I said,
|
By: Curtis Cooley
RE: Connecting a QByteArray to a QString [ reply ] 2011-03-15 15:33
|
Sorry for the confusion. I was using pseudo code but ended up just confusing the issue. The actual code:
require 'Qt'
class LogChop < Qt::Widget
slots "read()"
def initialize(parent = nil)
super(parent)
@filter = Qt::TextEdit.new(self)
@logs = Qt::Process.new(self)
connect(@logs, SIGNAL("readyReadStandardOutput()"), self, SLOT("read()"))
@logs.start "tail -f /var/log/messages"
end
def read
puts @logs.read_all_standard_output
log = @logs.read_all_standard_output
@filter.text = log
end
end
root = Qt::Application.new(ARGV)
chop = LogChop.new
chop.show
root.exec
This code will throw a "method missing" error because @logs.text= expects a QString and not a QByteArray. If I change it to say @logs.text="Hello World!" it works fine.
Good question about the QProcess. I tried just to use Thread but that didn't seem to work. I know GUI frameworks do not like other threads updating widgets in the main loop. It's why Java has SwingUtils.invokeLater(Runnable r). I thought perhaps QT was not allowing Threads it did not control to run. I'll go back to using Thread to try to get it to work. I'm not comfortable however updating widgets from the main loop's thread in another thread. Does QT handle that OK?
|
By: Janis-marie Newton
RE: Connecting a QByteArray to a QString [ reply ] 2011-03-15 05:51
|
you are presenting accurately what you are doing:
1) if this is was a ruby prg or even a c++ prg you could not call a method just by sticking a class name in front of (unless it is a static method). You do understand the concept of class instantiation?
2) I dont see a method read_all_standard_input for QProcess in any case???
3) why would you use QProcess, when ruby has its own native function to fork a process?
|
By: Curtis Cooley
RE: Connecting a QByteArray to a QString [ reply ] 2011-03-15 05:25
|
Thank you for the reply, Janis-marie. I may just be in over my head. I've tried things like:
logs = QProcess.read_all_standard_input
but that returns a QByteArray, so that's what logs is typed as. When I try to pass that along to QTextEdit.setPlainText(logs), I get an error :(
I'd like to just get ruby Strings, but I don't know how when all I have a reference to is a QByteArray.
I must be doing something wrong. This seems like it should be so much easier.
Is there a RubyQt wrapper for QByteArray that will hand me a ruby String?
Is there a reference I can consult so I'm not always asking these questions?
|
By: Janis-marie Newton
RE: Connecting a QByteArray to a QString [ reply ] 2011-03-14 22:32
|
Hi Curtis,
there is no wrapper for QString class from ruby. Just use a ruby string. And whenever you use a Qt class method that calls for a QString or QByteArray parameter just use a ruby string instead. the qtruby will make the convert and make the Qt class happy ;) Ex:
@addr = Qt::InputDialog::getText("Send E-Mail","Enter E-Mail Address(es):")
|
By: Curtis Cooley
Connecting a QByteArray to a QString [ reply ] 2011-03-14 17:01
|
Maybe I'm going about this all wrong. It is my first RubyQT and QT application.
I'm trying to build a simple remote file tail app. The only threading I've found in RubyQT is QProcess. I start a QProcess and connect it's signal to a local slot. When I read from the QProcess I get a QByteArray, but setPlainText on a QTextEdit takes a QString. How can I convert my QByteArray to a QString.
I've tried:
log = QString.new(output)
but no matter what syntax I use, I get an Unititialized constant QString error?
So, is there a better way to do this? If not, how can I convert a QByteArray to a QString in Ruby?
|
|
 |